Linux服務器中OpenSSH的源碼編譯與升級 |
發(fā)布時間: 2012/8/13 10:23:33 |
一。AS4升級步驟
1.建議使用源碼安裝方式,下載安裝包 cd/root wget-c"ftp://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-5.0p1.tar.gz" tarzxvfopenssh-5.0p1.tar.gz cdopenssh-5.0p1 2.升級請確認Zlib和OpenSSL的版本: openssh-5.0p1要求Zlib的版本在1.2.1.2以上,OpenSSL版本在0.9.6以上。下面是Zlib和OpenSSL的官方地址: http://www.gzip.org/zlib/ http://www.openssl.org/ 注意:OpenSSL0.9.5a屬于可接受的版本,但是在使用SSHprotocol1時,一些加密功能可能會出現(xiàn)問題(出于安全考慮,建議使用SSHprotocol2)。詳見INSTALL文檔。 3.編譯常用的參數(shù)——prefix=和——sysconfdir=,省略以上參數(shù),默認的ssh將安裝在/usr/local/bin下,sshd裝在/usr/local/sbin,sftp-server裝在/usr/local/libexec/sftp-server,配置文件在/usr/locale/etc下。 。/configure——sysconfdir=/etc/ssh make makeinstall 4.對比安裝默認和當前配置文件,個別重要參數(shù)請務必修改 diffsshd_config/etc/ssh.bak/sshd_config 5.配置文件推薦設置 確認/usr/local/libexec/sftp-server路徑是否正確 6.檢查配置文件的正確性 grep-v^#/etc/ssh/sshd_config|awk'{print$1}'|sort|uniq-d 是否有重復的行 /usr/local/sbin/sshd-t 參數(shù)是否正確 7.添加/etc/init.d腳本和service服務 先備份原來的腳本cp/etc/init.d/sshd/etc/init.d/sshd.bak 主要是修改ssh-keygen和sshd的路徑。PID文件也作相應修改,避免跟之前的sshd有沖突,這樣就能夠在保證原有sshd不受影響的情況下配置新的sshd服務。修改下面三項: 原來: KEYGEN=/usr/bin/ssh-keygen SSHD=/usr/sbin/sshd PID_FILE=/var/run/sshd.pid 改成: KEYGEN=/usr/local/bin/ssh-keygen SSHD=/usr/local/sbin/sshd PID_FILE=/var/run/sshd2.pid 添加service服務: /sbin/chkconfig——addsshd 8.重起sshd服務 注意:啟動新的sshd服務前,先臨時修改sshd_config里的端口,避免跟原有ssh端口沖突。 /sbin/servicesshdstart >/root/.ssh/known_hosts 用ssh登陸測試,如果能正常登錄就可以換回管理員使用的ssh端口(切換之前還是必須把舊版ssh占用的端口換掉)。 注意:遠程對ssh所做的任何重大修改,必須確保有另外的方式可以登錄服務器。 完成所有工作后,把原有的sshd服務關閉。 /etc/init.d/sshd.bakstop ssh升級完成,新版的/usr/local/sbin/sshd將代替舊版的/usr/sbin/sshd 如果不能登陸,請檢查。 1.啟動telnet服務 vi/etc/inetd.conf telnetstreamtcpnowaitroot/usr/libexec/telnetdtelnetd 檢查/etc/rc.conf中是否inetd_enable="YES,/etc/rc.d/inetdrestart,啟動inetd 用telnet登陸服務器,進行下面操作 2.升級openssh cd/root/ wget-cftp://ftp.openbsd.org/pub/OpenBS……penssh-5.0p1.tar.gz tarzxvfopenssh-5.0p1.tar.gz cdopenssh-5.0p1 。/configure——prefix=/usr——sysconfdir=/etc/ssh——libexecdir=/usr/libexec/openssh——without-zlib-version-check make makeinstall 對比安裝默認和當前配置文件,個別重要參數(shù)請務必修改 diffsshd_config/etc/ssh/sshd_config 檢查配置文件的正確性 grep-v^#/etc/ssh/sshd_config|awk'{print$1}'|sort|uniq-d 是否有重復的行 /usr/sbin/sshd-t 參數(shù)是否正確 重起sshd kill-HUP`cat/var/run/sshd.pid` 用ssh登陸檢查openssh服務是否安裝,啟動正常 關閉telnet服務,退出telnet killallinetd 確認telnet服務關閉 3.關于openssl的升級: 最新的openssl包,http://www.openssl.org/source/openssl-0.9.8g.tar.gz 可采用源碼安裝的形式, 。/config——prefix=/usr/local/openssl-0.9.8 make makeinstall 然后升級SSH,將——with-ssl-dir指向openssl的安裝目錄。 三。FAQ 啟動sshd服務的時候提示錯誤UnsupportedoptionUsePAM? 答:默認的configure沒有啟用——with-pam選項,如果在sshd_config配置文件里加入 UsePAMno就會導致上面的錯誤提示。UsePAM與ssh密碼認證相關,但公司服務器禁止通過密碼認證方式登錄。所以編譯的時候不建議使用——with-pam選項,配置文件里不使用UsePAMno,而改為使用 PasswordAuthenticationnoChallengeResponseAuthenticationno的方式來禁止密碼登錄。 本文出自:億恩科技【www.riomediacenter.com】 |