生成ssh密钥并把公钥发送给一组主机(SSH免密登录)

vim ip.txt
192.66.66.101
192.66.66.102
192.66.66.103
192.66.66.104
#!/usr/bin/bash
##2021/1/1
##ssh-key   lwq
get_keygen(){
/usr/bin/expct <<-EOF &>/dev/null
spawn  ssh-keygen
expect {

		".ssh/id_rsa):"  { send "\r"; exp_continue }
		"Overwrite (y/n)?" { send "y\r"; exp_continue }
		"no passphrase):"  { send "\r"; exp_continue }
		"passphrase again:"  {  send "\r" };

}
	interact
	expect eof
	EOF
}
send_key(){
/usr/bin/expct <<-EOF &>/dev/null
spawn  ssh-copy-id -i  $ip
expect {
		"connecting (yes/no)?"  { send "yes\r"; exp_continue}
		"password:"		{ send "1\r"}


}
	interact
	expect eof
EOF
}
echo "正在制作密钥"
echo "存放的ip的文件是ip.txt,对方密码是必须是1"
sleep 5

get_keygen
for ip  in $(cat ./ip.txt)
do 
	send_key $ip
	echo "$ip,密钥发送成功"
done
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值