环境介绍:
192.168.74.11 server1
192.168.74.12 server2
192.168.74.13 server3
# 步骤一:
# 每个节点执行
[root@localhost ~]# cat >>/etc/hosts <<EOF
192.168.74.11 server1
192.168.74.12 server2
192.168.74.13 server3
EOF
# 每个节点执行
ssh-keygen -t rsa # 一路回车
# 将公钥添加到认证文件中
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
# 并设置authorized_keys的访问权限
chmod 600 ~/.ssh/authorized_keys
# 拷贝公钥
ssh-copy-id -i 192.168.74.11 #登录server2,将公钥拷贝到server1的authorized_keys中
ssh-copy-id -i 192.168.74.11 #登录server3,将公钥拷贝到server1的authorized_keys中
# 注意第一次ssh登录时需要输入密码,再次访问时即可免密码登录。
最终authorized_keys文件内容如下:
more ~/.ssh/authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC/zyHwbBRxeB6BqXgecoWnWlNcXKqbdF+Pk1X1pNxXdXCNQrsaJQ54j+YzFNZ5IzxSEQ6yVTXSBqcYYilPMck2zMSlH6gU4+h1++LKHQwks