多台主机实现无秘钥操作 1、在每台主机上生成公钥秘钥,命令如下: (cd /root/.ssh) ssh-keygen -t rsa 一直按回车直到生成结束,将在/root/.ssh/目录下生成了两个文件 id_rsa 和 id_rsa.pub 2、在主节点上执行命令:cp id_rsa.pub authorized_keys 将公钥添加到authorized_keys 3、将子节点生成的公钥拷贝到主节点,命令如下:(在两台子机上执行) scp /root/.ssh/id_rsa.pub root@主节点名称:/root/.ssh/id_rsa_Mage2.pub scp /root/.ssh/id_rsa.pub root@host1:/root/.ssh/id_rsa_host2.pub
scp /root/.ssh/id_rsa.pub root@主节点名称:/root/.ssh/id_rsa_Mage3.pub scp /root/.ssh/id_rsa.pub root@host1:/root/.ssh/id_rsa_host3.pub 4、将拷贝过来的两个公钥合并到authorized_keys文件中去(cd /etc vi hosts),在主节点上执行如下命令:(在主机上执行) cat id_rsa_Mage2.pub>> authorized_keys cat id_rsa_host2.pub >> authorized_keys cat id_rsa_Mage3.pub>> authorized_keys cat id_rsa_host3.pub >> authorized_keys
5、将主节点的authorized_keys文件分别替换子节点的authorized_keys文件,在主节点上用scp命令将authorized_keys文件拷贝到子节点的相应位置:(在主机上执行) scp authorized_keys rootMage2:/root/.ssh/ scp authorized_keys root@host2:/root/.ssh/ scp authorized_keys rootMage3:/root/.ssh/ scp authorized_keys root@host3:/root/.ssh/ 6、测试是否配置成功,在主节点上执行如下命令: ssh host2 ssh host3