zoukankan      html  css  js  c++  java
  • centos6和centos7升级openssh7.5脚本

    #!/bin/bash
    #升级openssh版本
    
    #判断系统用户使用脚本
    
    if [ $(whoami) != "root" ]
    
        then
            echo -e "33[31mWarning : Can not use the current user operating! 33[0m"
            echo -e "33[31mWarning : Please use the 33[0m 33[32m root 33[0m 33[31muser! 33[0m"
            exit 1
    fi;
    
    
    #判断系统版本是否为x86_64
    
    platform=$(uname -i)
    if [ $platform != "x86_64" ];
        then 
            echo -e "33[31m this script is only for 64bit Operating System ! 33[0m"
            exit 1
    fi;
    
    echo -e "33[32m the platform is ok 33[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
    PasswordAuthentication 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
    pts/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
        
        cp contrib/redhat/sshd.init /etc/init.d/sshd
        
        chkconfig --add sshd
        
        echo "PermitRootLogin yes" >> /etc/ssh/sshd_config
        
        service sshd restart
    
    }
    
    
    #注意:centos7系统ssh服务升级完后运行此函数,关闭telnet服务
    function stop_xinetd()
    {
    
        centos=$(rpm -q centos-release|cut -d- -f3)
    
        if [ $centos -eq 6 ];
    
            then
    
                    sed '12d' /etc/xinetd.d/telnet
                    sed '11a disable         = yes' /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;
  • 相关阅读:
    Executors 构建线程池
    结构型模式——Bridge(未完成)
    结构型模式——Adapter
    创建型模式——Builder
    创建型模式——Abstract Factory
    Java与线程
    Java内存模型
    类加载
    Class类文件的结构
    垃圾收集器
  • 原文地址:https://www.cnblogs.com/opma/p/11607401.html
Copyright © 2011-2022 走看看