服务器批量配置免密,修改主机名

服务器批量配置免密,修改主机名

批量修改主机名

脚本内容如下:

#!/bin/bash
i=1
for group in `cat /home/group`
 do
  expect <<!
	spawn ssh root@$group
	expect {
		"yes/no" {send "yes\r"; exp_continue}
		"password:" {send "111111\r"; exp_continue}
	}
	send "hostnamectl set-hostname c$i\r"
	expect {
		"	" {send "y/n"; exp_continue}
	}
!
let i+=1
done

注:需要把所有服务器的ip,写入到脚本中的/home/group文件中。

批量配置服务器免密码登录

脚本一内容如下:

#!/bin/bash 

for group in `cat /home/group`
 do
  expect <<! 		
        spawn ssh root@$group
 	expect {
 	
 		"yes/no" { send "yes\r"; exp_continue}
 	
 		"password:" { send "111111\r"; exp_continue }
 	}
 	send "ssh-keygen -t rsa\r"
 	
	expect {
 		"/root/.ssh/id_rsa" { send "\n"; exp_continue}
 	
 		"Overwrite (y/n)?" { send "\n"; exp_continue}
 
		 "empty for no passphrase" { send "\n"; exp_continue}
	 
		 "Enter same passphrase again:" { send "\n"; exp_continue}
	 }
 
!
done

脚本二内容如下:

#!/bin/bash 
i=1
for group in `cat /home/group`
 do
  expect <<!            
	spawn  scp root@$group:/root/.ssh/id_rsa.pub /root/.ssh/public_key$i
        expect {
          "Are you sure you want to continue connecting (yes/no)? " { send "yes\r"; exp_continue}
          "password:" { send "111111\r"; exp_continue}
        }
 
!
cat /root/.ssh/public_key$i >> /root/.ssh/authorized_keys
  let i+=1
done

脚本三内容如下:

#!/bin/bash 
i=1
for group in `cat /home/group`
 do
  expect <<!            
        spawn  scp /root/.ssh/authorized_keys root@$group:/root/.ssh/
        expect {
          "Are you sure you want to continue connecting (yes/no)? " { send "yes\r"; exp_continue}
          "password:" { send "111111\r"; exp_continue}
        }
 
!
  let i+=1
done

注:需要把所有服务器的ip,写入到脚本中的/home/group文件中,按顺序执行脚本

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值