首先安装如下软件

yum -y install openssh-clients

否则没有 ssh-copy-id 命令


ssh-keygen  产生公钥与私钥对.

ssh-copy-id 将本机的公钥复制到远程机器的authorized_keys文件中,ssh-copy-id也能让你有到远程机器的home, ~./ssh , 和 ~/.ssh/authorized_keys的权利

该测试以root用户测试,如需其他用户的无密码SSH登录,执行切换到相应用户模式操作即可。


验证测试环境:

192.168.1.41 pgxlsrv1

192.168.1.42 pgxlsrv2

192.168.1.43 pgxlsrv3


第一步:在本地机器上使用ssh-keygen产生公钥私钥对

[root @pgxlsrv1 ~]# ssh-keygen

[root @pgxlsrv2 ~]# ssh-keygen

[root @pgxlsrv3 ~]# ssh-keygen


第二步:用ssh-copy-id将公钥复制到远程机器中

-i:指定公钥文件

#pgxlsrv1

[root @pgxlsrv1 ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@pgxlsrv1

[root @pgxlsrv1 ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@pgxlsrv2

[root @pgxlsrv1 ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@pgxlsrv3


#pgxlsrv2

[root @pgxlsrv2 ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@pgxlsrv2

[root @pgxlsrv2 ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@pgxlsrv1

[root @pgxlsrv2 ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@pgxlsrv3


#pgxlsrv3

[root @pgxlsrv3 ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@pgxlsrv3

[root @pgxlsrv3 ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@pgxlsrv1

[root @pgxlsrv3 ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@pgxlsrv2


注意: ssh-copy-id 将key写到远程机器的 ~/ .ssh/authorized_key.文件中


第三步登录到远程机器不用输入密码

#pgxlsrv1

[root @pgxlsrv1 ~]# ssh pgxlsrv1

[root @pgxlsrv1 ~]# ssh pgxlsrv2

[root @pgxlsrv1 ~]# ssh pgxlsrv3


#pgxlsrv2

[root @pgxlsrv2 ~]# ssh pgxlsrv2

[root @pgxlsrv2 ~]# ssh pgxlsrv1

[root @pgxlsrv2 ~]# ssh pgxlsrv3


#pgxlsrv3

[root @pgxlsrv3 ~]# ssh pgxlsrv3

[root @pgxlsrv3 ~]# ssh pgxlsrv1

[root @pgxlsrv3 ~]# ssh pgxlsrv2


------- 通过如上三步即可实现主机之间的无密码SSH登录 --------------