環境:Ubuntu 14.04.2
目的:openssh版本6.6升級為openssh7.9
准備以下3個包
http://www.zlib.net/
https://www.openssl.org/source/
http://www.openssh.com/portable.html
避免升級出現錯誤導致ssh服務掛掉,會導致一系列的麻煩事,所以提前安裝telnet服務
apt-get install openbsd-inetd telnetd telnet /etc/init.d/openbsd-inetd restart # 啟動服務 netstat -anpt|grep 23 # 查看telnet服務的默認端口是否啟動 telnet ip # 測試是否成功登陸
此處可能會遇到:安裝telnet 后,root登錄時總是提示 login incorrect
vim /etc/pam.d/login 注釋文件中的32行即可
上傳zlib源碼到服務器的任意目錄,並解壓 tar xf zlib-1.2.11.tar.gz ./configure --prefix=/usr/local/zlib make && make install
更新動態鏈接數據庫
echo "/usr/local/zlib/lib" >> /etc/ld.so.conf ldconfig -v
編譯安裝openssl
tar xf openssl-1.1.0k.tar.gz ./config shared && make && make install ln -s /usr/local/bin/openssl /usr/bin/openssl (注意此處軟鏈接需要按住實際路徑) ln -s /usr/local/include/openssl /usr/include/openssl(注意此處軟鏈接需要按住實際路徑) echo "/usr/local/ssl/lib" > /etc/ld.so.conf.d/openssl.conf ldconfig -v
查詢openssl版本號
編譯安裝openssh
tar xf openssh-7.9p1.tar.gz mv /etc/ssh /etc/ssh_bak (備份該目錄) mv /etc/init.d/ssh /etc/init.d/ssh_bak (備份該目錄) cd openssh-7.9p1/ ./configure --prefix=/usr --sysconfdir=/etc/ssh --with-md5-passwords --with-pam --with-zlib=/usr/local/zlib --with-ssl-dir=/usr/local --with-privsep-path=/var/lib/sshd make && make install
執行ssh -V驗證是否升級成功
拷貝源文件目錄中的sshd.init
cp -p contrib/redhat/sshd.init /etc/init.d/sshd
vim /etc/ssh/sshd_config 修改配置中的以下參數,使之和原來配置信息保持一致
Port 22 #PermitRootLogin prohibit-password PermitRootLogin yes
ln -s /lib/lsb/init-functions /etc/rc.d/init.d/functions
重啟service sshd restart,此處可以看到一個command not found的報錯,經過驗證該報錯不影響ssh服務啟動,暫時沒找到原因,經驗證ubuntu 16.04 及以上版本系統中沒有此問題。猜測是/etc/init.d/sshd配置文件中某個參數不對
執行以下命令查詢ssh服務是否正常啟動
ps -ef | grep ssh
netstat -lnutp|grep sshd
加入開機啟動項ubuntu中chkconfig已經被sysv-rc-conf替代
sysv-rc-conf sshd on
執行sysv-rc-conf --list|grep sshd命令驗證是否加入成功