加入收藏 | 设为首页 | 会员中心 | 我要投稿 51站长网 (https://www.51zhanzhang.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
站内搜索:
当前位置: 首页 > 服务器 > 搭建环境 > Linux > 正文

推荐一个Linux批量管理脚本

发布时间:2021-06-10 03:36:37 所属栏目:Linux 来源:互联网
导读:以下均放在/root目录下 (1) ip.txt 注意前面是IP,后面是密码,用冒号:分割,如果密码有冒号的建议单独处理 IP:密码 (2) remote_operate.sh #!/bin/bash #copyr

以下均放在/root目录下

(1) ip.txt

注意前面是IP,后面是密码,用冒号:分割,如果密码有冒号的建议单独处理

IP:密码 

(2) remote_operate.sh

#!/bin/bash 

#copyright by hwb  

 

if [ ! -d /root/.ssh ];then  

 mkdir /root/.ssh 

fi 

cat /tmp/authorized_keys >> /root/.ssh/authorized_keys 

(3) batch_sshkey.sh

#!/bin/bash 

#copyright by hwb  

 

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 "yesr"; exp_continue} 

 "*password*" {send "$passwordr"; exp_continue} 

 "*Password*" {send "$passwordr";} 

 } 

 

expect -c " 

spawn ssh root@$ip "/tmp/remote_operate.sh" 

 expect { 

 "*yes/no*" {send "yesr"; exp_continue} 

 "*password*" {send "$passwordr"; exp_continue} 

 "*Password*" {send "$passwordr";} 

 } 

done 

执行ssh-keygen,该命令会默认在~/.ssh/目录下创建id_rsa、id_rsa.pub两个文件,分别为公钥和私钥

ssh-keygen 

cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys 

(编辑:ASP站长)

【免责声明】本站内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。

    相关内容
    未处理完善
      无相关信息
    未处理完善