ansible建立ssh通道互信,实现无密码访问
用ansible工具建立 试试通道互信,实现无密码访问,只需要以下几步,就可以轻松实现ssh互信通道的建立。
1)在本地机器执行 ansible dbs -e 'ansible_host_key_checking=False' -m command -a "ssh-keygen -t rsa -f ~/.ssh/id_rsa -N ''" -f 3 #自动生成本地known_hosts内容,远程机器则没有
2)用ansible把所有机器的ssh的公钥copy到本地authorized_keys ansible dbs -m command -a 'cat /home/oracle/.ssh/id_rsa.pub' 2>/dev/null -f 3|grep -v 'CHANGED' >> /home/oracle/.ssh/authorized_keys
chmod 600 /home/oracle/.ssh/authorized_keys 赋权600
3)扫描个主机sshkey,追加到/home/oracle/.ssh/known_hosts ssh-keyscan dbnode-01,dbnode-02,dbnode-03 >> /home/oracle/.ssh/known_hosts
4)用ansible把本地的authorized_keys,known_hosts分发到其他机器上
ansible dbs --limit '!dbnode-03' -m copy -a 'src=/home/oracle/.ssh/authorized_keys dest=/home/oracle/.ssh/ mode=preserve' -f 2
ansible dbs --limit '!dbnode-03' -m copy -a 'src=/home/oracle/.ssh/known_hosts dest=/home/oracle/.ssh/ mode=preserve' -f 2
【完】

浙公网安备 33010602011771号