1. 生成公私密钥:
#ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
/root/.ssh/id_rsa already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
79:19:28:57:7a:77:4d:13:d3:f5:be:ef:2d:f4:a9:93 root@master
2. 复制生成的公钥到目的主机
#ssh-copy-id -i /root/.ssh/id_rsa.pub 192.168.18.22
21
The authenticity of host '192.168.18.22 (192.168.18.22)' can't be established.
RSA key fingerprint is 03:42:bf:93:34:15:37:8c:24:a8:1e:48:0f:bd:3a:43.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.18.22' (RSA) to the list of known hosts.
root@192.168.18.22's password:
Now try logging into the machine, with "ssh '192.168.18.22'", and check in:
.ssh/authorized_keys
to make sure we haven't added extra keys that you weren't expecting.
注意:如果目的主机ssh端口不是默认端口22, 如ssh端口为23456,则使用如下命令:
ssh-copy-id -i /root/.ssh/id_rsa.pub '-p 23456 root@192.168.18.22'
3. 查看known_hosts, 确认已经获得的主机
[root@master .ssh]# cat known_hosts
192.168.18.115 ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAx/FORptl/i5cvPyfM1nm4ixBjVU9Qur2K5oJobK9e/9Ml9EvfrZXNWmO7VIamNqI7Hvs5BEiByidG8KOou8G2rGuk74clMcuC+zkm6tRPPvFQ0nxWFlSvDU6KpFGBM8pbEt0cY9riQHu7RMIDS30/Q0xz9PlS6ddrvgEUQj+oLeSMfpjYs6VwE5TTa49/qf+awpZPGE/0VvKxyIK7Xh+3jQAXlYROyPhaka9FjvgRRKsRtYmTFMDd9Hs5trbbHieX+YOLdcomwzJaIQhbWpNGQ2kHlyHkr0L5iNPZUrsJj0eOcv3arYX4KGM1bGWYGDtaXnfVg3kr02JllodCL9nwQ==
192.168.18.22 ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA4WYfN/YtJp+Cb73UQe1yBvebEem9wBcw/myKNtWEdyLuaZ6Wyk8cJ7xic0Gf8Iabj2Kxfgm6shg8A586UVO2xhDFqJeUEeckylHXqdoGMzZGxMHFSxReIMzIY1JDvWy8TH35JM3/6IoJEXN3g7yILRcjympIPpSjsnpX/oLDGG18PymfCALy+tr0E5jSQkjS2fiGGODDBYkfSgZBc99+3Tgvj1i0LMCHoPLLvigpsiifrYdR0m+FroDEEZhI5SYC2AdOxHwgYEjOcSBoL10idQW7V+JNOA0GaVYBxD5QqmjdMqSgHkwXDNBjFiRb241ARzR5rf4O4OXzX3eKMdnJnQ==
阅读(4385) | 评论(0) | 转发(0) |