首页 > 代码库 > Linux sshssh免密码认证
Linux sshssh免密码认证
[root@localhost ~]# ssh-keygen -t rsa #创建密钥对
Generating public/private rsa key pair
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory ‘/root/.ssh‘.
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:
e0:19:93:d6:0d:fc:3f:7d:fd:b1:67:af:63:bc:d4:67 root@localhost.localdomain
The key‘s randomart image is:
+--[ RSA 2048]----+
| .. |
| o.o |
| * ... |
| o = . |
| o S . . .|
| o .oo|
| o..E|
| .+o=|
| .o=+|
+-----------------+
[root@localhost ~]# ssh-copy-id -i .ssh/id_rsa.pub root@10.0.0.20 #部署公钥到KVM服务器
The authenticity of host ‘10.0.0.20 (10.0.0.20)‘ can‘t be established.
ECDSA key fingerprint is c3:a2:bc:39:7d:a5:fd:f5:8a:93:28:fd:e6:4c:29:7b.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@10.0.0.20‘s password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh ‘root@10.0.0.20‘"
and check to make sure that only the key(s) you wanted were added.
[root@localhost ~]# ssh-copy-id -i .ssh/id_rsa.pub root@10.0.0.30 #部署公钥到KVM服务器
The authenticity of host ‘10.0.0.30 (10.0.0.30)‘ can‘t be established.
ECDSA key fingerprint is c3:a2:bc:39:7d:a5:fd:f5:8a:93:28:fd:e6:4c:29:7b.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@10.0.0.30‘s password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh ‘root@10.0.0.30‘"
and check to make sure that only the key(s) you wanted were added.
[root@localhost ~]#
[root@localhost ~]# ssh 10.0.0.20 #测试登陆服务器
Last login: Tue May 16 22:27:43 2017 from controller
[root@localhost ~]# ssh 10.0.0.30 #测试登陆服务器
Last login: Tue May 16 22:28:11 2017 from controller
本文出自 “gswcfl” 博客,请务必保留此出处http://guoshiwei.blog.51cto.com/2802413/1926443
Linux sshssh免密码认证