因爲項目構建時間比較長,近期安全檢查發現openssh有漏洞。因此要升級openssh到7.9p1版本。因爲ssh用於遠程鏈接,因此要謹慎操做。node
一、 依賴安裝安全
OpenSSL版本:目前OpenSSH7.9不支持OpenSSH1.1.x以上。不然編譯的時候會報錯。bash
Zlib1.1.4或1.2.1.2或更高版本;服務器
gcc:由於編譯須要gcc;ssh
openssl-devel:編譯時須要spa
二、下載openssh 7.9rest
wget https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-7.9p1.tar.gz
三、卸載舊的opehsshcode
rpm -qa |grep openssh rpm -e --nodeps openssh-clients-7.4p1-11.el7.x86_64 rpm -e --nodeps openssh-7.4p1-11.el7.x86_64 rpm -e --nodeps openssh-server-7.4p1-11.el7.x86_64 rpm -qa |grep openssh
若是以前就是源碼安裝的,找到以前的安裝包,在裏面執行cdn
make uninstall
四、解壓並安裝server
4.1)解壓
tar xf openssh-7.9p1.tar.gz cd openssh-7.9p1 4.2)編譯 ./configure --prefix=/usr --sysconfdir=/etc/ssh --with-md5-passwords --with-privsep-path=/var/lib/sshd
make
注意!!!
注意!!!
注意!!!
① configure: error: no acceptable C compiler found in $PATH
問題解決
yum install gcc
② configure: error: * zlib.h missing - please install first or check config.log *
問題解決
安裝相關依賴包
yum install openssl openssl-devel -y
4.3)修改文件權限不然會安裝報錯
chmod 600 /etc/ssh/ssh_host_rsa_key
chmod 600 /etc/ssh/ssh_host_ecdsa_key
chmod 600 /etc/ssh/ssh_host_ed25519_key
4.4)安裝
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*
install -v -m644 INSTALL LICENCE OVERVIEW README* /usr/share/doc/openssh-7.9p1
命令解釋:
--sysconfdir=/etc/ssh:這能夠防止安裝配置文件 /usr/etc。
--with-md5-passwords:這使得可使用MD5密碼。
--with-pam:此參數在構建中啓用 Linux-PAM支持。
--with-xauth=/usr/bin/xauth:爲X身份驗證設置xauth二進制文件的默認位置。若是將xauth安裝到其餘路徑,請更改位置。這也能夠sshd_config使用XAuthLocation關鍵字進行控制。若是已安裝Xorg,則能夠省略此開關。
--with-kerberos5=/usr:此選項用於在構建中包含Kerberos 5支持。
--with-libedit:此選項爲sftp啓用行編輯和歷史記錄功能。
六、根據自身需求改寫配置文件。由於配置文件爲初始配置文件。因此和以前的不同。可使用備份配置文件覆蓋。
注意:
默認是22端口,可是不能root直接登陸。若是想直接使用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
八、重啓服務器
reboot
腳本:
該腳本在確認好本機環境的狀況後執行 !!!
cat openssh_7.9.1_update.sh
#!/bin/bash rpm -qa |grep zlib rpm -qa |grep openssl rpm -qa |grep openssh gcc --version read -p "是否繼續[y/n]" Check if [ $Check == 'y' ] then for rpmpkgs in `rpm -qa |grep openssh`; do rpm -e --nodeps ${rpmpkgs} ;done sleep 1 rpm -qa |grep openssh mkdir /tmp/opensshupdate -p cd /tmp/opensshupdate && wget https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-7.9p1.tar.gz ./configure --prefix=/usr --sysconfdir=/etc/ssh --with-md5-passwords --with-privsep-path=/var/lib/sshd make sleep 1 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 sleep 1 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* install -v -m644 INSTALL LICENCE OVERVIEW README* /usr/share/doc/openssh-7.9p1 sleep 1 echo "PermitRootLogin yes" >> /etc/ssh/sshd_config sleep 1 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 else break fi