ssh+批量分发

注意:.ssh权限700 公钥authorized_keys权限600

#先安装wget
yum -y install wget  
#yum云搭建
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
yum -y clean all
yum makecache
#安装sshpass(yum云才有)
yum -y install sshpass

#ssh非交互的两条命令
ssh-keygen -t dsa -f ~/.ssh/id_dsa -P ""
sshpass -p "对方账号密码" ssh-copy-id -i ~/.ssh/id_dsa.pub "-o StrictHostKeyChecking=no [email protected](对方ip)"
yum -y install openssh-clients &> /dev/null
#ping通的网,批量分发密钥
ping -c 1 www.baidu.com &> /dev/null
if [ $? -eq 0 ];then
	ssh-keygen -t dsa -f ~/.ssh/id_dsa -P ""
	for ip in `ping -c 1 ${wd}{1..254}`
	do
  		if [ $? -eq 0 ];then 
			sshpass -p " " ssh-copy-id -i ~/.ssh/id_dsa.pub "-o StrictHostKeyChecking=no root@$ip"
		fi
	done
else
	echo "没网络"
fi

猜你喜欢

转载自blog.csdn.net/weixin_44439515/article/details/89351436