linux服务器之间ssh免密码设置

应用场景:test01 ssh访问test02,不需要输入密码

 

登录test01

 

第一步:生成公钥、私钥

[root@test01 ~]# 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:
b8:cf:14:8f:ae:69:2a:fb:ba:1a:60:d8:8a:f8:4c:1a root@test01
[root@test01 ~]#

 

 

第二步:复制公钥到被管理的服务器test02

 

[root@test01 ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub "[email protected]"
21
The authenticity of host '192.168.1.19 (192.168.1.19)' can't be established.
RSA key fingerprint is a7:47:b2:f6:e7:ef:8f:2c:9d:9c:03:74:de:3b:e1:55.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.19' (RSA) to the list of known hosts.
[email protected]'s password:
Now try logging into the machine, with "ssh '[email protected]'", and check in:

  .ssh/authorized_keys

to make sure we haven't added extra keys that you weren't expecting.

[root@test01 ~]#

 

最后就可以直接 ssh [email protected] 登录test02,而不用再输入密码

 

你可能感兴趣的:(linux)