cd /root wget -c "ftp://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-5.0p1.tar.gz" tar zxvf openssh-5.0p1.tar.gz cd openssh-5.0p1
需 Zlib ≥ 1.2.1.2、OpenSSL ≥ 0.9.6。官方下載:Zlib、OpenSSL。OpenSSL 0.9.5a 可接受但 SSHv1 部分加密可能有問題,建議強制使用 SSHv2。
常用參數:--prefix(安裝前綴)、--sysconfdir(配置目錄)。預設行為:ssh→/usr/local/bin、sshd→/usr/local/sbin、sftp-server→/usr/local/libexec/sftp-server、配置→/usr/local/etc。
推薦編譯:
./configure --sysconfdir=/etc/ssh make make install
diff sshd_config /etc/ssh.bak/sshd_config
重要參數務必手動調整。
# 檢查重複配置行
grep -v ^# /etc/ssh/sshd_config | awk '{print $1}' | sort | uniq -d
# 驗證參數語法
/usr/local/sbin/sshd -t
備份原腳本:cp /etc/init.d/sshd /etc/init.d/sshd.bak。修改三項路徑:
| 項目 | 原路徑 | 新路徑 |
|---|---|---|
| KEYGEN | /usr/bin/ssh-keygen | /usr/local/bin/ssh-keygen |
| SSHD | /usr/sbin/sshd | /usr/local/sbin/sshd |
| PID_FILE | /var/run/sshd.pid | /var/run/sshd2.pid |
添加服務:/sbin/chkconfig --add sshd
注意:啟動前先臨時修改 sshd_config 端口避免與舊版衝突。
/sbin/service sshd start > /root/.ssh/known_hosts
SSH 登入測試正常後,切回管理員用埠(先釋放舊版佔用埠)。
遠端修改 SSH 必須確保有備用登入方式。
完成後關閉舊服務:/etc/init.d/sshd.bak stop。新版 /usr/local/sbin/sshd 取代舊版 /usr/sbin/sshd。
/etc/inetd.conf 加入 telnet stream tcp nowait root /usr/libexec/telnetd telnetd,確認 /etc/rc.conf 有 inetd_enable="YES",重啟 /etc/rc.d/inetd restart,用 telnet 登入操作cd /root/ wget -c ftp://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-5.0p1.tar.gz tar zxvf openssh-5.0p1.tar.gz cd openssh-5.0p1 ./configure --prefix=/usr --sysconfdir=/etc/ssh --libexecdir=/usr/libexec/openssh --without-zlib-version-check make && make install對比配置、驗證語法、重啟:
kill -HUP `cat /var/run/sshd.pid`,SSH 測試無誤後關閉 telnet:killall inetd./config --prefix=/usr/local/openssl-0.9.8 && make && make install,升級 SSH 時 --with-ssl-dir 指向 OpenSSL 安裝目錄問題:啟動 sshd 提示 "Unsupported option UsePAM"?
解答:預設 configure 未啟用 --with-pam。若配置檔加 UsePAM no 會報錯。因公司伺服器禁止密碼認證,編譯不建議加 --with-pam,改用以下禁止密碼登入:
PasswordAuthentication no ChallengeResponseAuthentication no