利用sshpass批量实现基于key验证脚本

实现基于key验证的脚本1:

[root@centos7 ~]#vim /etc/ssh/ssh_config
# 免应答known_hosts
StrictHostKeyChecking no 

[root@centos7 ~]#cat hosts.list
192.168.1.210
192.168.1.211

[root@centos7 ~]#vim push_ssh_key.sh
#!/bin/bash
rpm -q sshpass &> /dev/null || yum -y install sshpass  
[ -f /root/.ssh/id_rsa ] || ssh-keygen -f /root/.ssh/id_rsa  -P ''
export SSHPASS=123456
while read IP;do
   # -e参数通过前面SSHPASS定义密码
   sshpass -e ssh-copy-id  -o StrictHostKeyChecking=no $IP
done < hosts.list

实现基于key验证的脚本2:

IPLIST="
10.0.0.8
10.0.0.18
10.0.0.7
10.0.0.6
10.0.0.200"
# 判断是否有sshpass包
rpm -q sshpass &> /dev/null || yum -y install sshpass  

[ -f /root/.ssh/id_rsa ] || ssh-keygen -f /root/.ssh/id_rsa  -P ''
export SSHPASS=centos
for IP in $IPLIST;do
   # -e参数通过前面SSHPASS定义密码
   sshpass -e ssh-copy-id -o StrictHostKeyChecking=no $IP
done
posted @ 2023-02-06 16:59  taotaozh  阅读(84)  评论(0编辑  收藏  举报