linux 批量升级openssh8.0

Posted xl-892694298

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux 批量升级openssh8.0相关的知识,希望对你有一定的参考价值。

updateopenssh.sh

explujing=/home/updateopenssh.exp     
username=root                              
password=123456                         
                                     
iplist="
192.167.1.94
192.167.1.95
192.167.1.96
192.167.1.97
"                                    
port=22                             
for ip in $omplist              
do                                   
  $explujing $ip $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 [email protected]$desthost
expect "*assword:*"
send "$password\r"
expect
 "*(yes/no)?"
 
   send "yes\n"
   expect "*assword:" send "$password\n"
 
   "*assword:"
 
    send "$password\n"
 
 
expect "*#"
send "scp [email protected]:/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
 
 

以上是关于linux 批量升级openssh8.0的主要内容,如果未能解决你的问题,请参考以下文章

运维自动化之 - ansible 批量主机管理

Spring批量管理升级

分享一次OPENssh批量升级过程和升级脚本

sql 批量插入和升级

批量安装可升级包

DELL RACADM 批量升级戴尔IDRAC固件