Linux之ssh无密码登录
简单方式实现,多台Linux主机之间ssh无密码登录。
1.在任意一台主机上执行如下命令。如:192.168.10.102
1 [root@RS1 ~]# ssh-keygen 2 Generating public/private rsa key pair. 3 Enter file in which to save the key (/root/.ssh/id_rsa): 4 Created directory '/root/.ssh'. 5 Enter passphrase (empty for no passphrase): 6 Enter same passphrase again: 7 Your identification has been saved in /root/.ssh/id_rsa. 8 Your public key has been saved in /root/.ssh/id_rsa.pub. 9 The key fingerprint is: 10 d4:7d:81:58:48:3b:32:cc:1a:d7:66:87:35:cc:36:54 root@RS1 11 The key's randomart image is: 12 +--[ RSA 2048]----+ 13 | ..B=oE | 14 | o oo=*. . | 15 | . B O.o.. | 16 | = = o . | 17 | . S | 18 | | 19 | | 20 | | 21 | | 22 +-----------------+ 23 [root@RS1 ~]#
2.继续在该主机(192.168.10.102)上执行如下命令:
1 [root@RS1 ~]# ssh-copy-id root@192.168.10.102 2 The authenticity of host '192.168.10.102 (192.168.10.102)' can't be established. 3 RSA key fingerprint is 1b:99:fa:98:48:0e:bd:86:94:dc:33:4d:f2:8c:f0:56. 4 Are you sure you want to continue connecting (yes/no)? yes 5 Warning: Permanently added '192.168.10.102' (RSA) to the list of known hosts. 6 root@192.168.10.102's password: 7 Now try logging into the machine, with "ssh 'root@192.168.10.102'", and check in: 8 9 .ssh/authorized_keys 10 11 to make sure we haven't added extra keys that you weren't expecting. 12 13 [root@RS1 ~]#
3.:将该主机上的.ssh文件夹拷贝到其他主机上,即可实现各主机相互之间的ssh无密码登录
1 [root@RS1 ~]# scp -r .ssh root@192.168.10.103:~/.ssh 2 The authenticity of host '192.168.10.103 (192.168.10.103)' can't be established. 3 RSA key fingerprint is 1b:99:fa:98:48:0e:bd:86:94:dc:33:4d:f2:8c:f0:56. 4 Are you sure you want to continue connecting (yes/no)? yes 5 Warning: Permanently added '192.168.10.103' (RSA) to the list of known hosts. 6 root@192.168.10.103's password: 7 id_rsa 100% 1675 1.6KB/s 00:00 8 authorized_keys 100% 390 0.4KB/s 00:00 9 known_hosts 100% 792 0.8KB/s 00:00 10 id_rsa.pub 100% 390 0.4KB/s 00:00 11 [root@RS1 ~]#