实现:A、B两台linux服务器,A可以直接ssh 服务器B

原理:公钥加密,私钥解密。将A的公钥拷贝到B服务器,当A ssh远程B时,B会通过A的公钥加密,生成随机数,并发送给A。A通过自己的私钥进行解密。

步骤:1、

A、B服务器执行ssh-keygen命令生成相应的公钥私钥

[root@VCS_Goo1 ~]# ssh-keygen

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:
27:a9:9b:d6:59:12:1a:82:89:f2:4e:6f:bb:5b:aa:2b root@VCS_Goo1

2、

A服务器:

[root@VCS_Goo1 ~]#scp /root/.ssh/id_rsa.pub B服务器ip:/root/.ssh

3、

B服务器:

[root@VCS_Goo2 ~]#cd /root/.ssh

 [root@VCS_Goo2  .ssh]#mv id_rsa.pub authorized.keys    //将A的公钥改名 authorized.keys

4、验证

在A服务器上通过ssh远程B服务器,发现不用输入B服务器的密码也可以。

(PS:如果想实现B服务器无密码远程A服务器,方法类似)