批量免密码
ansible批量免秘登录
https://www.cnblogs.com/qiangyuzhou/p/10552016.html
sshpass
#!/bin/bash rpm -q sshpass &> /dev/null || yum install sshpass -y sed -i "s/StrictHostKeyChecking ask/StrictHostKeyChecking no/" /etc/ssh/ssh_config [ -f /root/.ssh/id_rsa ] || ssh-keygen -f /root/.ssh/id_rsa -P '' export SSHPASS=123.com while read IP;do ssh-pass -e ssh-copy-id $IP done < host.list
1.使用 ssh-keygen -t rsa生成密钥对
ssh-keygen -t rsa
2.配置将客户端信息加到ansible得hosts配置文件中
[test] 192.168.252.213 ansible_ssh_user=root ansible_ssh_pass=1qaz@WSX
[all:vars] ansible_ssh_user=sdn ansible_ssh_pass=1qaz@WSX
检测连接
ansible test -m ping
3.ansible服务端配置生成公钥,执行以下命令然后一直回车即可。
ssh-keygen -t rsa
4.配置ansible剧本文件push-ssh.yml
# Using alternate directory locations: - hosts: tomcat-servers user: tomcat (互信用户) tasks: - name: ssh-copy authorized_key: user=tomcat(互信用户) key="{{ lookup('file', '/home/tomcat/.ssh/id_rsa.pub(master端公钥)') }}" tags: - sshkey
- name: 修改权限
shell: chmod 600 ~/.ssh/authorized_keys
5.使用ansible-playbook命令执行以上push-ssh.yml剧本文件看效果
6.验证ssh登录客户端是否免密。
ssh root@192.168.253.3