centos6 and centos7 upgrade script openssh7.5

! # / bin / bash 
# upgrade openssh version 

# judging system users using a script 

IF [$ ( whoami ) =! " root " ] 

    the then 
        echo -e " \ 033 [31mWarning: of Can not use the User at The Current Operating \ 033 [0m! " 
        echo -e " ! \ 033 [31mWarning: Please use at The \ 033 [0m \ 033 [32M root \ 033 [0m \ 033 [31muser \ 033 [0m " 
        Exit 1 
fi ; 


# judging system version is x86_64 

Platform = $ ( the uname - I)
 IF [Platform = $! " the x86_64 " ];
     the then 
        echo -e "\033[31m this script is only for 64bit Operating System ! \033[0m"
        exit 1
fi;

echo -e "\033[32m the platform is ok \033[0m"

cat << EOF
+---------------------------------------+
|   your system is CentOS x86_64      |
|      start optimizing.......          |
+---------------------------------------+
EOF



function centos6()
{

    yum install telnet-server -y

    sed '12d' /etc/xinetd.d/telnet
    sed '11a disable         = no' /etc/xinetd.d/telnet

    service xinetd restart                  

    yum install gcc -y

    yum install openssl-devel -y

    yum install wget -y
    
    #project_path=$(cd `dirname $0`; pwd)
    
    mkdir -p /opt/ssh_update
    
    cd /opt/ssh_update/
    
    wget http://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-7.5p1.tar.gz
    
    #tar -zxvf $project_path/openssh-7.5p1.tar.gz
    
    tar -zxvf /opt/ssh_update/openssh-7.5p1.tar.gz
    
    cd /opt/ssh_update/openssh-7.5p1/
    
    ./configure
    
    make && make install
    
    cp /etc/init.d/sshd /etc/init.d/sshd_$(date +"%Y%m%d_%H%M%S")
    
    sed -i 's#SSHD=/usr/sbin/sshd#SSHD=/usr/local/sbin/sshd#' /etc/init.d/sshd
    
    echo -e "PermitRootLogin yes\nPasswordAuthentication yes" >> /usr/local/etc/sshd_config
    
    mv /usr/bin/ssh  /usr/bin/ssh_$(date +"%Y%m%d_%H%M%S")
    
    mv /usr/local/bin/ssh /usr/bin/ssh
    
    /etc/init.d/sshd restart
    
    #/usr/local/sbin/sshd -t -f /usr/local/etc/sshd_config

}


function centos7()
{

    yum install -y telnet-server
    yum install -y xinetd 
    
    systemctl enable xinetd.service
    systemctl enable telnet.socket
    systemctl start telnet.socket
    
    echo -e "pts/0\npts/1"  >> /etc/securetty
    
    systemctl start xinetd
    
    firewall-cmd --zone=public --add-port=23/tcp --permanent
    firewall-cmd --reload
    
    yum -y install pam-devel.x86_64 zlib-devel.x86_64
    
    yum install gcc -y
    
    yum install openssl-devel -y
    
    yum install wget -y
    
    mv /etc/ssh/ /etc/ssh_$(date +"%Y%m%d_%H%M%S")
    
    mkdir -p /opt/ssh_update
    
    cd /opt/ssh_update/
    
    wget http://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-7.5p1.tar.gz
    
    tar -zxvf openssh-7.5p1.tar.gz
    
    cd /opt/ssh_update/openssh-7.5p1
    
    ./configure --prefix=/usr --sysconfdir=/etc/ssh
    
    make 
    
    rpm -e --nodeps `rpm -qa | grep openssh`
    
    make install
    
    cpcontrib / RedHat / sshd.init /etc/init.d/ sshd
    
    chkconfig - the Add sshd 
    
    echo  " PermitRootLogin yes " >> / etc / ssh / sshd_config 
    
    Service sshd restart 

} 


# Note: centos7 ssh service upgrade system after running this function, Close telnet service 
function stop_xinetd () 
{ 

    CentOS = $ (RPM CentOS-Release -q | Cut -D-- F3) 

    IF [$ CentOS -eq . 6 ]; 

        the then 

                Sed  ' 12 d ' /etc/xinetd.d/ telnet
                 Sed  ' Yes = disable 11a ' /etc/xinetd.d/ Telnet
                service xinetd restart        

        else

                systemctl disable xinetd.service
                systemctl disable telnet.socket
                systemctl stop telnet.socket
                systemctl stop xinetd
                firewall-cmd --zone=public --remove-port=23/tcp --permanent
                firewall-cmd --reload
    fi;

}


if [ "$1" = "stop_xinetd" ]; then

    stop_xinetd;

fi;

if [ "$1" = "update" ]; then

    centos=$(rpm -q centos-release|cut -d- -f3)

    if [ $centos -eq 6 ];

        then

            centos6;

        else

            centos7;
    fi;
fi;

 

Guess you like

Origin www.cnblogs.com/opma/p/11607401.html