centos三台主机配置互信ssh登录

1. 修改hosts信息

1.1三台主机上分别修改hosts文件

vi /etc/hosts

1.2 三台主机分别填入如下内容,ip地址需要检查正确

192.168.126.223 node1
192.168.126.224 node2
192.168.126.225 node3

2. 秘钥生成和分发

2.1 在三台主机上分别生成秘钥

命令输入后,按三次回车即可

ssh-keygen -t rsa

2.2 分发秘钥

2.2.1 node1上输入命令,分发秘钥到node2和node3

ssh-copy-id -i /root/.ssh/id_rsa.pub node2
ssh-copy-id -i /root/.ssh/id_rsa.pub node3

2.2.2 node2上输入命令,分发秘钥到node1和node3

ssh-copy-id -i /root/.ssh/id_rsa.pub node1
ssh-copy-id -i /root/.ssh/id_rsa.pub node3

2.2.3 node3上输入命令,分发秘钥到node1和node2

ssh-copy-id -i /root/.ssh/id_rsa.pub node1
ssh-copy-id -i /root/.ssh/id_rsa.pub node2

3. 验证结果

node1节点上验证,先后输入ssh node2然后exit登出node2,ssh node3然后exit登出node3,如果能正常进行,那么node1免密登录node2和node3成功。
node2和node3在分别验证即可。

你可能感兴趣的:(centos,ssh,linux)