在实际生产环境中我们往往在一些维护时需要多台Linux主机相互连接,那此时就需要做ssh的免密码互信认证,而ssh的免密的互信认证实现比较简单,在此就简单的描述下,为描述方便我把内网中的2台需要做ssh互信认证的2台主机192.168.2.25、192.168.2.26这2台主机,其中以192.168.2.25作为master连接其它主机,以192.168.2.26作为slave,操作如下:

[root@localhost ~]# vim /etc/ssh/sshd_config#2台主机上把以下3行的注释去掉
…略…
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile      .ssh/authorized_keys
…略…
[root@localhost ~]# /etc/init.d/sshd restart

192.168.2.25(master):

[root@localhost ~]# ssh-keygen -t rsa#提示全部回车
[root@localhost ~]# cd .ssh/
[root@localhost .ssh]# cat id_rsa.pub >> authorized_keys
[root@localhost .ssh]# chmod 600 authorized_keys#修改下authorized_keys权限

192.168.2.26(slave):

[root@localhost ~]# cd .ssh/
[root@localhost .ssh]# scp 192.168.2.25:~/.ssh/authorized_keys ./#把master上的authorized_keys拷贝过来
[root@localhost .ssh]# chmod 600 authorized_keys

做好互信证书认证后master就可以直接免密码直连slave