[摘自知乎,亲测清晰好使]
安装ansible,取消key检测
yum install ansible -y
vim /etc/ansible/ansible.cfg
host_key_checking = False
[root@test ~]# cat /etc/ansible/hosts
[all:vars]
ansible_ssh_user=root
ansible_ssh_pass=redhat(被控节点账号密码,密码建议设置相同)
[test]
192.168.19.142
生成密钥
ssh-keygen -t rsa
选择文件/root/.ssh/id_rsa
密码就空着
注意前后的变化
[root@test .ssh]# ls
id_rsa id_rsa.pub known_hosts
[root@test .ssh]# ssh-copy-id 192.168.19.148 (ansible管控节点IP)
[root@test .ssh]# ls
authorized_keys id_rsa id_rsa.pub known_hosts
批量推送
ansible all -m authorized_key -a "user=root exclusive=true manage_dir=true key='$(</root/.ssh/authorized_keys)'"
验证
ssh 192.168.19.142
网友评论