linux ssh 批量,linux 批量升级openssh8.0

updateopenssh.sh

ckmsce=/home/updateopenssh.exp

username=root

password=123456

omplist="

192.167.1.94

192.167.1.95

192.167.1.96

192.167.1.97

"

port=23

for ompname in $omplist

do

$ckmsce $ompname $username $password $port

done

#-------------------------------------

updateopenssh.exp

#!/usr/bin/expect -f

set date [exec date -d day +'%Y%m%d']

set desthost [lindex $argv 0]

set username [lindex $argv 1]

set password [lindex $argv 2]

set port [lindex $argv 3]

spawn ssh -D $port $username@$desthost

expect "*assword:*"

send "$password\r"

expect {

"*(yes/no)?"

{

send "yes\n"

expect "*assword:" {send "$password\n"}

}

"*assword:"

{

send "$password\n"

}

}

expect "*#"

send "scp root@192.167.1.74:/root/openssh-8.0p1.tar.gz /root/ \r"

expect {

"*(yes/no)?"

{

send "yes\n"

expect "*assword:" {send "$password\n"}

}

"*assword:"

{

send "$password\n"

}

}

expect "100%"

send "cd /etc/\r"

expect "*#"

send "rm -rf ssh_bak\r"

expect "*#"

send "cd /etc/init.d/\r"

expect "*#"

send "rm -rf sshd_bak\r"

expect "*#"

send "mv /etc/ssh /etc/ssh_bak\r"

expect "*#"

send "/etc/init.d/sshd /etc/init.d/sshd_bak\r"

expect "*#"

send "cd /root/\r"

expect "*#"

send "tar xfz openssh-8.0p1.tar.gz\r"

sleep 3;

expect "*#"

send "cd /root/openssh-8.0p1/\r"

expect "*#"

send -- "./configure --prefix=/usr --sysconfdir=/etc/ssh --with-md5-passwords--with-pam --with-tcp-wrappers  --with-ssl-dir=/usr/local/ssl --without-hardening\r"

sleep 80;

expect "*#"

send "make\r"

sleep 80;

expect "*#"

send "make install\r"

sleep 80

expect "*#"

send "yes | cp -a opensshd.init  /etc/init.d/sshd\r"

sleep 2;

expect "*#"

send "chmod +x /etc/init.d/sshd\r"

sleep 1;

expect "*#"

send "cat /etc/ssh/sshd_config | grep Per\r"

sleep 1;

expect "*#"

send "echo  \'PermitRootLogin yes\' >> /etc/ssh/sshd_config\r"

sleep 1;

expect "*#"

send "chmod +x /etc/init.d/sshd\r"

sleep 2;

expect "*#"

send "service sshd restart\r"

sleep 2;

expect "*#"

send "service sshd restart\r"

sleep 2;

interact

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值