Ansible配置免密登陸
阿新 • • 發佈:2017-12-23
bsp chan hang 獲取 免密登錄 true oot scan all
0x01: 把遠程服務器的公鑰來獲取到本地
#ssh-keyscan ip1 ip2 ip3 ip4 >> /root/.ssh/known_hosts
完成後,/root/.ssh/known_hosts 多了許多內容
0x02: 添加服務IP到 ansible 的 hosts
#cat >> /etc/ansible/hosts << EOF ip1 ip2 ip3 ip4 EOF #
0x03: 添加免密登錄(我的ROOT密碼都一樣,使用 -k 參數, 然後輸入 root 密碼)
ansible all -m authorized_key -a "user=root state=present key=\"{{ lookup(‘file‘, ‘/root/.ssh/id_rsa.pub‘) }} \"" -k
0x04: 驗證免密登陸
#ansible all -m ping 172.16.13.5 | SUCCESS => { "changed": false, "failed": false, "ping": "pong" } 172.16.13.15 | SUCCESS => { "changed": false, "failed": false, "ping": "pong" } 172.16.13.6 | SUCCESS => { "changed": false, "failed": false, "ping": "pong" } 172.16.13.8 | SUCCESS => { "changed": false, "failed": false, "ping": "pong" } 172.16.13.9 | SUCCESS => { "changed": false, "failed": false, "ping": "pong" } #
Ansible配置免密登陸