CentOS7-升級OpenSSH
安裝前須知的命令說明
systemctl 如何啟動、關閉、啟用/禁用服務
啟動服務:systemctl start xxx.service
關閉服務:systemctl stop xxx.service
重啟服務:systemctl restart xxx.service
顯示服務的狀態:systemctl status xxx.service
在開機時啟用服務:systemctl enable xxx.service
在開機時禁用服務:systemctl disable xxx.service
查看服務是否開機啟動:systemctl is-enabled xxx.service
查看已啟動的服務列表:systemctl list-unit-files|grep enabled
查看啟動失敗的服務列表:systemctl --failed
1.準備好安裝需要的包
下載openssh包和openssl的包(友情提示:迅雷下載會快哦)
openssh版本openssh-xxx.tar.gz:https://openbsd.hk/pub/OpenBSD/OpenSSH/portable/
openssl版本openssl-xxx.tar.gz:https://ftp.openssl.org/source/
注意:openssh和openssl版本對應關系請自行搜索
我這里用的是:
openssh-8.3p1.tar.gz
openssl-1.1.1g.tar.gz
2.解壓
# tar xfz openssh-8.3p1.tar.gz
# tar xfz openssl-1.1.1g.tar.gz
3.安裝依賴包
升級需要幾個組件,有些是和編譯相關的等
# yum install? -y gcc gcc-c++ glibc make autoconf openssl openssl-devel pcre-devel? pam-devel
安裝pam和zlib等
# yum install? -y pam* zlib*
4.安裝telnet
為防止openssh升級失敗。所以安裝telnet。保證openssh升級失敗也可以通過telnet連接服務器,進行恢復操作。并不用去機房。
# yum install -y telnet-server
# yum install -y xinetd
# systemctl start telnet.socket
# systemctl start? xinetd
建議開啟telnet和xinetd開機自動啟動,避免reboot后連不上Telnet
# systemctl enable xinetd.service
# systemctl enable telnet.socket
CentOS 7 采用了 firewalld 防火墻,查詢是否開啟23端口
# firewall-cmd --query-port=23/tcp
顯示23端口沒有開啟使用下面命令開啟23端口
# firewall-cmd --zone=public --add-port=23/tcp --permanent
重新加載firewall-cmd
# firewall-cmd --complete-reload
重新查詢23端口是否開放
# firewall-cmd --query-port=23/tcp
驗證telnet
使用遠程telnet連接驗證
5.安裝openssl
? 備份
? # mv /usr/bin/openssl /usr/bin/openssl_bak
? # mv /usr/include/openssl /usr/include/openssl_bak
? 編譯安裝
? # cd openssl-1.1.1g
? # ./config --prefix=/usr/local/openssl??--shared?
? # make && make? install
? 命令執行完畢,echo $?查看下最后的make install是否有報錯,0表示沒有問題
? # echo $?
? 下面2個文件或者目錄做軟鏈接?(剛才前面的步驟mv備份過原來的)
? # ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl
? # ln -s /usr/local/openssl/include/openssl /usr/include/openssl
? 命令行執行下面2個命令加載新配置
? # echo "/usr/local/openssl/lib" >> /etc/ld.so.conf
? # /sbin/ldconfig
? 查看確認版本。
? # openssl version
6.安裝openssh
? 安裝前須知
? 需要把selinux關閉,使用命令getenforce查看selinux狀態,Enforcing為開啟,Permissive為關閉
? # getenforce
? 臨時關閉selinux
? setenforce 0
? 永久關閉selinux,需要重啟服務器
? vi /etc/selinux/config
? 將SELINUX=enforcing改為SELINUX=disabled
? 注:友情提示,不關閉selinux會出bug的
? 卸載舊的ssh
? # cp -r /etc/ssh /etc/ssh.old #備份一些之前的文件
? # rpm -qa|grep openssh
? # rpm -e --nodeps openssh-clients-6.6.1p1-31.el7.x86_64 (版本可能不一樣,以實際為主)
? # rpm -e --nodeps openssh-6.6.1p1-31.el7.x86_64 (版本可能不一樣,以實際為主)
? # rpm -e --nodeps openssh-server-6.6.1p1-31.el7.x86_64 (版本可能不一樣,以實際為主)
? # rpm -qa|grep openssh
? 連接到其他計算機時,OpenSSH作為兩個進程運行。第一個進程是特權進程,并根據需要控制權限? 的頒發。第二個進程與網絡通信。設置適當的環境需要額外的安裝步驟,這些步驟通過以root用戶身份發出以下命令來執行 :
? # install -v -m700 -d /var/lib/sshd
? # chown -v root:sys /var/lib/sshd
? # groupadd -g 50 sshd
? # useradd -c 'sshd PrivSep' -d /var/lib/sshd -g sshd -s /bin/false -u 50 sshd
? 編譯
? # cd openssh-8.3p1
? # ./configure --prefix=/usr/ --sysconfdir=/etc/ssh? --with-openssl-includes=/usr/local/openssl/include? --with-ssl-dir=/usr/local/openssl? --with-zlib? --with-md5-passwords? --with-pam? && make
? 修改相應文件權限
? # chmod 600 /etc/ssh/ssh_host_rsa_key
? # chmod 600 /etc/ssh/ssh_host_ecdsa_key
? # chmod 600 /etc/ssh/ssh_host_ed25519_key
? 安裝
? # make install
? 安裝完畢?檢查下結果
? # echo $?
? 配置
? # install -v -m755 contrib/ssh-copy-id /usr/bin
? # install -v -m644 contrib/ssh-copy-id.1 /usr/share/man/man1
? # install -v -m755 -d /usr/share/doc/openssh-8.3p1
? # install -v -m644 INSTALL LICENCE OVERVIEW README* /usr/share/doc/openssh-8.3p1
? 修改sshd_config,最下面添加如下幾個配置:
? # vi /etc/ssh/sshd_config
? UsePAM no
? UseDNS no
? PasswordAuthentication yes
? PubkeyAuthentication yes
? 配置啟動設置和開機啟動
? ? # cp -p contrib/redhat/sshd.init /etc/init.d/sshd
? ? # cp -p contrib/redhat/sshd.pam /etc/pam.d/sshd.pam
? ? # chmod +x /etc/init.d/sshd
? ? # chkconfig --add sshd
? ? # chkconfig sshd on
? ? # chkconfig --list sshd
? ? # systemctl restart sshd
? 驗證ssh
? # ssh -V
7.關閉telnet服務
# systemctl disable xinetd.service
# systemctl disable telnet.socket
# systemctl stop xinetd.service
# systemctl stop telnet.socket
8.回滾操作
如果之前是rpm包安裝的。并且按照以上步驟操作,可以直接以下命令進行回滾
# yum -y install openssh-clients
# yum -y install openssh-server
# yum -y install openssh
9.文檔有用的話記得點個贊哦-.-,有什么問題也可以下方評論
參考
http://www.lxweimin.com/p/220f7fd908b0
https://blog.csdn.net/popboy126/article/details/107247527
https://www.cnblogs.com/activiti/p/7552677.html (selinux 相關操作)
https://blog.csdn.net/sdd220/article/details/78296219 (CentOS7-開啟端口)