ssh+批量分发

本文详细介绍如何在Linux环境下使用SSH进行非交互式密钥生成与批量分发,包括安装必要软件、设置正确的文件权限、生成及分发公钥到多个远程服务器,实现免密码登录。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

注意:.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 root@192.168.200.130(对方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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值