CentOS7ssh互信

一、在A机上配置

①以root用户登录,更改ssh配置文件

vi /etc/ssh/sshd_config

RSAAuthentication yes #启用rsa认证
PubkeyAuthentication yes #启用公钥私钥配对认证方式
AuthorizedKeysFile .ssh/authorized_keys #公钥文件路径

systemctl restart sshd //重启ssh服务

②生成公钥私钥对

ssh-keygen -t rsa

系统在/root/.ssh下生成id_rsa、id_rsa.pub

③把A机下的id_rsa.pub发送到A、B、C机

ssh-copy-id -i /root/.ssh/id_rsa.pub 192.168.10.122
ssh-copy-id -i /root/.ssh/id_rsa.pub 192.168.10.125
ssh-copy-id -i /root/.ssh/id_rsa.pub 192.168.20.11

二、B、C机采用步骤一中相同的方法,要记得改变ip地址

三、实现ssh多机互信

以A机为例

ssh 192.168.10.122  //登录B机
ifconfig //检查是否成功登录
exit //退出ssh登录,返回本机

添加新的机器

新机器D:

①以root用户登录,更改ssh配置文件

②生成公钥私钥对

③把D机下的id_rsa.pub发送到A机

分发A机的.ssh/authorized_keys到其他机器上