centos 批量ssh免密登录配置
ssh-keygen -t dsa -f /root/.ssh/id_dsa -N ""
安装sshpass工具
yum -y install sshpass
vi fenfa.sh
#!/bin/bash
# author:wei
# 2020-9-125
# description:SSH密钥批量分发
User=root
passWord=123
A=172.16.0.13
B=172.16.0.14
C=172.16.0.18
function YumBuild(){
echo "正在安装epel源yum仓库,请稍后..."
cd /etc/yum.repos.d/ &&\
[ -d bak ] || mkdir bak
[ `find ./*.* -type f | wc -l` -gt 0 ] && find ./*.* -type f | xargs -i mv {} bak/
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo &>/dev/null
yum -y clean all &>/dev/null
yum makecache &>/dev/null
}
echo "正在创建密钥对...."
rm -rf ~/.ssh/id_dsa ~/.ssh/id_dsa.pub
ssh-keygen -t dsa -f ~/.ssh/id_dsa -P "" &>/dev/null
for ip in $A $B $C
do
ping $ip -c1 &>/dev/null
if [ $? -gt 0 ];then
echo "$ip无法ping通请检查网络"
continue
fi
sshpass -p $passWord ssh-copy-id -i ~/.ssh/id_dsa.pub -o StrictHostKeyChecking=no ${User}@$ip &>/dev/null
echo "$ip 密钥分发成功"
done
浙公网安备 33010602011771号