Linux批量部署无密钥脚本
作者:网络转载 发布时间:[ 2015/6/1 13:19:10 ] 推荐标签:操作系统
##### 批量部署ssh私钥认证 #####
一、首先安装expect,直接yum即可
二、批量部署ssh私钥脚本
batch_sshkey.sh
==============================================================
#!/bin/bash
cd /root
cat /root/.ssh/id_rsa.pub > /root/.ssh/authorized_keys
for i in `cat ip.txt`
do
ip=$(echo "$i"|cut -f1 -d":")
password=$(echo "$i"|cut -f2 -d":")
expect -c "
spawn scp /root/.ssh/authorized_keys /root/remote_operate.sh root@$ip:/tmp/
expect {
"*yes/no*" {send "yes
"; exp_continue}
"*password*" {send "$password
"; exp_continue}
"*Password*" {send "$password
";}
}
"
expect -c "
spawn ssh root@$ip "/tmp/remote_operate.sh"
expect {
"*yes/no*" {send "yes
"; exp_continue}
"*password*" {send "$password
"; exp_continue}
"*Password*" {send "$password
";}
}
"
done
============================================================
ip.txt(前面是IP,后面是密码,用冒号:分割)
192.168.8.23:123456
192.168.8.24:456789
============================================================
remote_operate.sh
#!/bin/bash
if [ ! -d /root/.ssh ];then
mkdir /root/.ssh
fi
cp /tmp/authorized_keys /root/.ssh/
==========================================================
运行batch_sshkey.sh即可。
batch_sshkey.sh设置可执行权限,需./执行,执行过程中无需按回车,自动会完成部署。
相关推荐
更新发布
功能测试和接口测试的区别
2023/3/23 14:23:39如何写好测试用例文档
2023/3/22 16:17:39常用的选择回归测试的方式有哪些?
2022/6/14 16:14:27测试流程中需要重点把关几个过程?
2021/10/18 15:37:44性能测试的七种方法
2021/9/17 15:19:29全链路压测优化思路
2021/9/14 15:42:25性能测试流程浅谈
2021/5/28 17:25:47常见的APP性能测试指标
2021/5/8 17:01:11