环境:

服务器A(172.16.1.2)

服务器B(172.16.1.3)


在服务器A

1.执行生成秘钥命令

[root@localhost ~]#ssh-keygen -t rsa

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:

0f:79:e3:71:60:54:d7:1e:77:e7:36:97:9c:21:da:82 root@localhost

The key's randomart p_w_picpath is:

+--[ RSA 2048]----+

|          ... .. |

|         .   o o=|

|          + o ooO|

|         E + . ==|

|        S + o  .o|

|         = +     |

|          o      |

|                 |

|                 |

+-----------------+


执行完后会在/root/.ssh/目录下生成两个文件

-rw------- 1 root root 1675 Dec  9 21:42 id_rsa

-rw-r--r-- 1 root root  391 Dec  9 21:42 id_rsa.pub


2.传送秘钥给服务器B

[root@localhost ~]#scp /root/.ssh/id_rsa.pub root@172.16.1.3:/root/.ssh/authorized_keys

root@172.16.1.3's password:                     #这次需要输入密码


3.测试

[root@localhost .ssh]# ssh root@172.16.1.3

Last login: Tue Dec  9 21:52:54 2014 from 172.16.1.3         

[root@Good ~]#                                  #这次不用输入密码了



如果服务器B也需要不用密码ssh到服务器A的话,直接参考以上步骤即可

注:如果服务器A需要与多台ssh信任,直接把其他服务器上生成的秘钥内容复制到服务器A上authorized_keys里即可