centos6,centos7離線升級openssh到最新版本


打包下載:

telnet+vsftp+openssh,centos的離線rpm安裝包和依賴包,離線升級openssh教程

tcentos6升級openssh到7.9版本,centos7升級openssh到8.2版本

下載鏈接


把package上傳到家目錄

1.安裝telnet服務和客戶端
    
    1.1按順序執行
        cd ~/package/telnet
        rpm -Uvh xinetd-2.3.15-13.el7.x86_64.rpm
        rpm -Uvh telnet-server-0.17-64.el7.x86_64.rpm
        rpm -Uvh telnet-0.17-64.el7.x86_64.rpm
    
    1.2啓用telnet服務
        ccentos6:
        vi /etc/xinetd.d/telnet
        將其中disable字段的yes改爲no以啓用telnet服務
        centos7:
        systemctl enable telnet.socket
    
    1.3默認情況下,系統是不允許root用戶telnet遠程登錄的。如果要使用root用戶直接登錄,需設置如下內容:
        echo  'pts/0'  >>/etc/securetty
        echo 'pts/1' >>/etc/securetty
        
        註釋該行
        vi /etc/pam.d/remote
        #auth       required     pam_securetty.so
    
    1.4啓動並設置開機自啓
        centos6:
        service xinetd start
        chkconfig xinetd on
        centos7:
        systemctl start telnet.socket
    
    1.5測試是否能連接。通過其他linux機器或者Windows cmd窗口,需要安裝telnet客戶端
        telnet ip
        
        補充:輸入用戶名密碼正確的情況下提示Login incorrect
            修改/etc/pam.d/remote,註釋掉:auth  required  pam_securetty.so
            再重啓xinetd
        centos6:
        service xinetd restart
        centos7:
        systemctl restart telnet.socket
    
2.安裝ftp服務
    2.1.安裝vsftp
    
        cd ~/package/vsftp
        rpm -Uvh vsftpd-3.0.2-25.el7.x86_64.rpm
        rpm -Uvh ftp-0.17-67.el7.x86_64.rpm
        
        報錯error: Failed dependencies:libcrypto.so.10()(64bit) is needed by vsftpd-2.2.2-24.el6.x86_64
        該服務器上沒有安裝openssl,先安裝openssl-1.0.1e-57.el6.x86_64.rpm,可以先執行步驟3.3安裝依賴包
        
    2.2.關閉selinux,先臨時關閉,再永久關閉,已經是關閉的就不用管了
    
        臨時關閉:
        setenforce 0
    
        永久關閉:
        vi /etc/sysconfig/selinux
        SELINUX=enforcing 改爲 SELINUX=disabled
    
    2.3.先備份原有vsftpd.conf
        mv /etc/vsftpd/vsftpd.conf /etc/vsftpd/vsftpd.conf.old
        
        增加和修改配置
        vi /etc/vsftpd/vsftpd.conf
        local_root=/home/cent
        allow_writeable_chroot=YES
        
    2.4.增加ftp賬戶
        這裏設置的賬戶名爲“cent”,密碼爲“cent”,密碼需要輸入兩遍
        useradd cent -s /sbin/nologin
        passwd cent
        Qwer1234.
        
    2.5.編輯user_list文件,允許cent用戶訪問FTP
        vi /etc/vsftpd/user_list
        最後一行添加一個用戶cent
    
    2.6.開啓vsftpd服務並設置開機自啓
    centos6:
        service vsftpd start
        chkconfig vsftpd on
    centos7:
        systemctl enable vsftpd
        systemctl start vsftpd
    2.7測試是否能夠上傳文件
        測試工具有xftp,連接時選擇ftp方式,端口號21,用戶名和密碼都是cent
        ftp工具filezilla
        必須要保證能夠上傳文件
        文件會上傳到local_root=/home/cent

3.升級openssh
        
    3.1斷開當前連接的ssh窗口,使用telnet方式連接服務器,需要驗證用戶名和密碼
        telnet ip
        
    3.2停止ssh服務,卸載當前openssh,一定要確保telnet和ftp兩個服務跑起來並設置了開機自啓以防止服務器突然關機導致連不上機器
        centos6:
        service sshd stop
        rpm -e --nodeps `rpm -qa|grep openssh` 
        centos7:
        systemctl stop sshd
        rpm -e --nodeps `rpm -qa|grep openssh` 
        
        以前的配置文件,安裝完後可以恢復它
        warning: /etc/ssh/ssh_config saved as /etc/ssh/ssh_config.rpmsave
        warning: /etc/ssh/sshd_config saved as /etc/ssh/sshd_config.rpmsave
        
    3.3安裝依賴包,進入文件夾~/package/openssh/dependencies2
        cd ~/package/openssh/dependencies2
        rpm -Uvh *.rpm --nodeps --force
        
    3.4解壓
        進入文件夾
        cd ~/package/openssh
        tar -zxf openssh-8.2p1.tar.gz
        
    3.5編譯和安裝
        進入解壓的目錄
        cd openssh-8.2p1
        ./configure --prefix=/usr --sysconfdir=/etc/ssh --with-pam --with-zlib --with-md5-passwords 
        make && make install
        
        centos7:
        報錯sshd: no hostkeys available -- exiting.
        有這兩文件就chmod,沒有就生成,百度查一下
        chmod 600 /etc/ssh/ssh_host_dsa_key
        chmod 600 /etc/ssh/ssh_host_rsa_key
        在執行命令make && make install
        
    3.6複製pam文件,複製啓動腳本,設置開機自啓
        cp contrib/redhat/sshd.pam /etc/pam.d/sshd
        cp contrib/redhat/sshd.init /etc/init.d/sshd
        
        centos6:
        chkconfig sshd on
        
        centos7:
        systemctl enable sshd
        
    3.7配置ssh_config
        vi /etc/ssh/sshd_config
        PermitRootLogin yes  #允許root用戶通過ssh登陸
        PubkeyAuthentication yes #公鑰授權
        PasswordAuthentication yes #密碼授權
        
    3.8驗證版本信息
        ssh -V
        
    3.9啓動ssh服務
        centos6:
        service sshd start
        centos7:
        systemctl start sshd
        
    3.10測試ssh服務是否正常
        使用xshell嘗試連接服務器
        再重啓ssh服務
        service sshd restart
        
        斷開連接再重新連接服務器
        
4.關閉telnet
    4.1關閉telnet,關閉開機自啓
        centos6:
        service xinetd stop
        chkconfig xinetd off
        
        centos7:
        systemctl stop telnet.socket
        systemctl disable telnet.socket
    4.2刪除用戶組pts/0和pts/1
        vi /etc/securetty
        最後兩個pts/0和pts/1刪除
        
    4.3如果修改了/etc/pam.d/remote
        打開註釋
        vi /etc/pam.d/remote
        auth       required     pam_securetty.so

5.關閉ftp並刪除用戶
    5.1打開selinux,如果原來就是關閉的,就不用管它
        setenforce 1
        
        vi /etc/sysconfig/selinux
        SELINUX=disabled 改爲 SELINUX=enforcing
        
    5.2關閉ftp服務,禁止開機自啓
        centos6:
        service vsftpd stop
        chkconfig vsftpd off
        centos7:
        systemctl stop vsftpd
        systemctl disable vsftpd
        
    5.3刪除用戶cent和該用戶家目錄
        userdel -r cent

        
 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章