ssh-keygen -t rsa [-P ‘‘] [-f “~/.ssh/id_rsa"]
## -r rsa:指定算法
## -P :加对称秘钥口令
## -f :可以指定生成路径
## /.ssh/id_rsa 生成秘钥默认路径
我们简单操作就不加密码了
[root@centos7 .ssh]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
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:
SHA256:Y9ia1CPAxegHbp767h8I5iLKCpLxuHxZxB7gfWSIkLw root@centos7
The key‘s randomart image is:
+---[RSA 2048]----+
|..o .oo |
| o +oo.o |
| oo*.o |
| E .+*.= |
|. oooo* S |
| B .o= = o |
|B o.+ + |
|Bo.o . |
|=o.++.. |
+----[SHA256]-----+
查看生成的公钥和私钥
[root@centos7 .ssh]#ls
id_rsa id_rsa.pub
## id_rsa私钥
## id_rsa.pub公钥
二、把公钥文件传输至远程服务器
ssh-copy-id [-i [公钥文件]] [user@]host
如果传输时写时误传了私钥文件系统会自动转换成公钥文件传输,不用紧张
三、测试
[root@centos5 .ssh]#ssh 192.168.27.6
Last login: Sun Jan 14 17:04:42 2018 from 192.168.27.1
[root@centos6 ~]#
登陆成功
原文:http://blog.51cto.com/13574131/2060925