目录

 

一、简介

二、安装putty步骤

2.1、通过连接下载远程登录服务器软件:

2.2、安装puTTy

2.3、运行PuTTy

2.4、查看服务器ip ifconfig

2.5、输入ip连接服务器

二、使用密钥认证机制远程登录linux

2.1、简介

2.2、配置

2.2.1、生成密钥对

2.2.2、设置linux服务器

2.2.3、配置putty,root无密码登录


一、简介

  • Linux一般用来做服务器使用,而服务器一般放在机房,你不可能在机房操作你的 Linux 服务器。
  • 这时我们就需要远程登录到Linux服务器来管理维护系统。
  • Linux 系统中是通过 ssh 服务实现的远程登录功能,默认 ssh 服务端口号为 22。
  • Window 系统上 Linux 远程登录客户端有 SecureCRT, Putty, SSH Secure Shell 等,本文以 Putty 为例来登录远程服务器。

二、安装putty步骤

2.1、通过连接下载远程登录服务器软件:

远程登陆centos en_zh改为wn_us centos如何远程登录_密钥对

2.2、安装puTTy

远程登陆centos en_zh改为wn_us centos如何远程登录_远程登录_02

2.3、运行PuTTy

远程登陆centos en_zh改为wn_us centos如何远程登录_服务器_03

2.4、查看服务器ip ifconfig

  • inet 网络
  • netmask 掩码
  • broadcast 广播

 

[root@localhost ~]# ifconfig
eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
网卡代号
        inet 192.168.83.130  netmask 255.255.255.0  broadcast 192.168.83.255
        ip地址/网关/子网掩码

        inet6 fe80::20c:29ff:fee1:7461  prefixlen 64  scopeid 0x20<link>
        IPv6的地址

        ether 00:0c:29:e1:74:61  txqueuelen 1000  (Ethernet)
        RX packets 16315  bytes 21061661 (20.0 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 6926  bytes 483016 (471.6 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        接受包数量/出错数量/丢失数量...

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 76  bytes 6612 (6.4 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 76  bytes 6612 (6.4 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

virbr0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255
        ether 52:54:00:a3:6d:28  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@localhost ~]#

2.5、输入ip连接服务器

下面的框中输入你要登录的远程服务器IP(ifconfig命令查看服务器ip)

远程登陆centos en_zh改为wn_us centos如何远程登录_密钥对_04

远程登陆centos en_zh改为wn_us centos如何远程登录_密钥对_05

二、使用密钥认证机制远程登录linux

2.1、简介

  • SSH 为 Secure Shell 的缩写,由 IETF 的网络工作小组(Network Working Group)所制定。
  • SSH 为建立在应用层和传输层基础上的安全协议。

2.2、配置

2.2.1、生成密钥对

首先使用工具 PUTTYGEN.EXE 生成密钥对。打开工具 PUTTYGEN.EXE 后如下图所示:

远程登陆centos en_zh改为wn_us centos如何远程登录_远程登录_06

 

远程登陆centos en_zh改为wn_us centos如何远程登录_远程登录_07

该工具可以生成五种格式的key :RSA\ DSA\ECDSA\Ed25519\(SSH-1)RSA ,我们采用默认的格式即RSA。Number of bits in a generated key 这个是指生成的key的大小,这个数值越大,生成的key就越复杂,安全性就越高。此处默认为 2048。

远程登陆centos en_zh改为wn_us centos如何远程登录_密钥对_08

单击Generate 开始生成密钥对:

远程登陆centos en_zh改为wn_us centos如何远程登录_服务器_09

生成的密钥对

远程登陆centos en_zh改为wn_us centos如何远程登录_密钥对_10

至此密钥对已经成功生成,可以给密钥输入一个密码(Key Passphrase出输入密钥的密码)也可以留空。然后点 Save public key 保存公钥,点 Save private Key 保存私钥。应该把它放在一个比较安全的地方,一防止别人偷窥,二防止误删除。

2.2.2、设置linux服务器

1、创建目录/root/.ssh/top并设置权限

[root@localhost ~]# mkdir /root/.ssh/top/  在/root/.ssh目录下创建top文件
[root@localhost ~]# cd /root/.ssh
[root@localhost .ssh]# ls -l
total 0
drwxr-xr-x. 2 root root 6 Nov 27 23:17 top

删除所有用户的执行权(x)
[root@localhost .ssh]# chmod a-x top
[root@localhost .ssh]# ll
总用量 0
drw-r--r--. 2 root root 6 11月 27 23:17 top



给属主授权rwx  给属组授权rx   给其他用户授权rx

[root@localhost top]# chmod u=rwx,g-rx,o=rx top
chmod: cannot access ‘top’: No such file or directory
[root@localhost top]# cd ..
[root@localhost .ssh]# chmod u=rwx,g=rx,o=rx top
[root@localhost .ssh]# ll
total 0
drwxr-xr-x. 2 root root 6 Nov 27 23:17 top

2、创建文件authorized_keys

 vim 命令是编辑一个文本文件的命令

[root@localhost ~]# vim /root/.ssh/anthorized_keys
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
"~/.ssh/anthorized_keys" [New File]
  • 打开刚才生成的anthorized_keys 文件,建议使用写字板打开,这样看着舒服一些,复制从AAAA开头至 "---- END SSH2 PUBLIC KEY ----" 该行上的所有内容,粘贴到/root/.ssh/authorized_keys 文件中,要保证所有字符在一行。(可以先把复制的内容拷贝至记事本,然后编辑成一行载粘贴到该文件中)。
  • 在这里要简单介绍一下,如何粘贴,用vim打开那个文件后,该文件不存在,所以vim会自动创建。按一下字母"i"然后同时按shift + Insert 进行粘贴(或者单击鼠标右键即可),前提是已经复制到剪切板中了。粘贴好后,然后把光标移动到该行最前面输入 ssh-rsa ,然后按空格。再按ESC,然后输入冒号wq 即 :wq 就保存了。格式如下图:

远程登陆centos en_zh改为wn_us centos如何远程登录_服务器_11

2.2.3、配置putty,root无密码登录

再设置putty选项,点窗口左侧的SSh –> Auth ,单击窗口右侧的Browse… 选择刚刚生成的私钥, 再点Open ,此时输入root,就不用输入密码就能登录了。

远程登陆centos en_zh改为wn_us centos如何远程登录_远程登录_12

远程登陆centos en_zh改为wn_us centos如何远程登录_密钥对_13

如果在前面设置了Key Passphrase ,那么此时就会提示输入密码的。为了更加安全建议设置一个Key Passphrase。