天天看點

centos-7更新 openssh-server 到7.9

由于某些傻X的掃描,需要更新openssh-server.

其實不需要更新的,centos7 支援到2024年,如果有什麼漏洞,官方肯定會出修複,如果自行安裝ssh7.9,那就需要自己進行更新和維護工作。參見:https://unix.stackexchange.com/questions/486153/upgrade-openssh-7-4-to-later-on-rhel

主要參考: https://www.jianshu.com/p/220f7fd908b0

此文檔提到安裝telnet防止更新失敗,經過實際檢驗,如果沒有異常,可以不需安裝telnet

#準備工作
yum install gcc
yum install openssl openssl-devel -y   #安裝依賴包

#下載下傳openssh.位址是:https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/

 wget https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-7.9p1.tar.gz
#編譯 
 tar -zxvf openssh-7.9p1.tar.gz
 cd openssh-7.9p1
 ./configure --prefix=/usr --sysconfdir=/etc/ssh --with-md5-passwords --with-privsep-path=/var/lib/sshd
 make


#安裝openssh
 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

 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

 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-7.9p1
 install -v -m644 INSTALL LICENCE OVERVIEW README* /usr/share/doc/openssh-7.9p1


#允許root登陸
 echo "PermitRootLogin yes" >> /etc/ssh/sshd_config

#開機自啟動
 cp -p contrib/redhat/sshd.init /etc/init.d/sshd
 chmod +x /etc/init.d/sshd
 chkconfig --add sshd
 chkconfig sshd on
 chkconfig --list sshd

 systemctl restart sshd

 
           

  systemctl restart sshd 這一步要注意,如果在登入ssh中發現問題可以執行 systemctl status sshd 檢視問題所在

 我遇到的問題是 error: Could not get shadow information for root

 原因是更改ssh端口導緻SELINUX 阻止,解決方法是 

  setenforce 0 #臨時關閉Selinux

  如果要永久關閉,修改/etc/selinux/config 檔案,

将SELINUX=enforcing改為SELINUX=disabled

#驗證操作
 ssh -V
 #輸出 OpenSSH_7.9p1, OpenSSL 1.0.2k-fips 26 Jan 2017
 
 
 #復原 (一旦出錯還可以還原)
 yum -y install openssh-clients
 yum -y install openssh-server
 yum -y install openssh
           

參考:

https://www.jianshu.com/p/220f7fd908b0

繼續閱讀