


Linux服務(wù)器中OpenSSH的源碼編譯與升級(jí)
一。AS4 升級(jí)步驟
1.建議使用源碼安裝方式,下載安裝包
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
2.升級(jí)請確認(rèn)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/
注意: OpenSSL 0.9.5a屬于可接受的版本,但是在使用SSH protocol 1 時(shí),一些加密功能可能會(huì)出現(xiàn)問題(出于安全考慮,建議使用SSH protocol 2)。詳見INSTALL文檔。
3.編譯常用的參數(shù)——prefix=和——sysconfdir=,省略以上參數(shù),默認(rèn)的ssh將安裝在 /usr/local/bin下,sshd裝在/usr/local/sbin,sftp-server裝在/usr/local/libexec/sftp-server,配置文件在/usr/locale/etc下。
。/configure ——sysconfdir=/etc/ssh
make
make install
4.對比安裝默認(rèn)和當(dāng)前配置文件,個(gè)別重要參數(shù)請務(wù)必修改
diff sshd_config /etc/ssh.bak/sshd_config
5.配置文件推薦設(shè)置
確認(rèn)/usr/local/libexec/sftp-server路徑是否正確
6.檢查配置文件的正確性
grep -v ^# /etc/ssh/sshd_config | awk '{print $1}' | sort | uniq -d
是否有重復(fù)的行
/usr/local/sbin/sshd -t
參數(shù)是否正確
7.添加/etc/init.d腳本和service服務(wù)
先備份原來的腳本cp /etc/init.d/sshd /etc/init.d/sshd.bak
主要是修改ssh-keygen和sshd的路徑。PID文件也作相應(yīng)修改,避免跟之前的sshd有沖突,這樣就能夠在保證原有sshd不受影響的情況下配置新的sshd服務(wù)。修改下面三項(xiàng):
原來:
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服務(wù):
/sbin/chkconfig ——add sshd
8.重起sshd服務(wù)
注意:啟動(dòng)新的sshd服務(wù)前,先臨時(shí)修改sshd_config里的端口,避免跟原有ssh端口沖突。
/sbin/service sshd start
>/root/.ssh/known_hosts
用ssh登陸測試,如果能正常登錄就可以換回管理員使用的ssh端口(切換之前還是必須把舊版ssh占用的端口換掉)。
注意:遠(yuǎn)程對ssh所做的任何重大修改,必須確保有另外的方式可以登錄服務(wù)器。
完成所有工作后,把原有的sshd服務(wù)關(guān)閉。
/etc/init.d/sshd.bak stop
ssh升級(jí)完成,新版的/usr/local/sbin/sshd將代替舊版的/usr/sbin/sshd
如果不能登陸,請檢查。
二。openSSH升級(jí)步驟:
1.啟動(dòng)telnet服務(wù)
vi /etc/inetd.conf
telnet stream tcp nowait root /usr/libexec/telnetd telnetd
檢查/etc/rc.conf中是否inetd_enable="YES,/etc/rc.d/inetd restart,啟動(dòng)inetd
用telnet登陸服務(wù)器,進(jìn)行下面操作
2.升級(jí)openssh
cd /root/
wget -c ftp://ftp.openbsd.org/pub/OpenBS …… penssh-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
對比安裝默認(rèn)和當(dāng)前配置文件,個(gè)別重要參數(shù)請務(wù)必修改
diff sshd_config /etc/ssh/sshd_config
檢查配置文件的正確性
grep -v ^# /etc/ssh/sshd_config | awk '{print $1}' | sort | uniq -d
是否有重復(fù)的行
/usr/sbin/sshd -t
參數(shù)是否正確
重起sshd
kill -HUP `cat /var/run/sshd.pid`
用ssh登陸檢查openssh服務(wù)是否安裝,啟動(dòng)正常
關(guān)閉telnet服務(wù),退出telnet
killall inetd
確認(rèn)telnet服務(wù)關(guān)閉
3.關(guān)于openssl的升級(jí):
最新的openssl包,http://www.openssl.org/source/openssl-0.9.8g.tar.gz
可采用源碼安裝的形式,
。/config ——prefix=/usr/local/openssl-0.9.8
make
make install
然后升級(jí)SSH,將 ——with-ssl-dir指向openssl的安裝目錄。
三。FAQ
啟動(dòng)sshd 服務(wù)的時(shí)候提示錯(cuò)誤Unsupported option UsePAM?
答:默認(rèn)的configure沒有啟用——with-pam選項(xiàng),如果在sshd_config配置文件里加入
UsePAM no 就會(huì)導(dǎo)致上面的錯(cuò)誤提示。UsePAM與ssh密碼認(rèn)證相關(guān),但公司服務(wù)器禁止通過密碼認(rèn)證方式登錄。所以編譯的時(shí)候不建議使用——with-pam選項(xiàng),配置文件里不使用UsePAM no,而改為使用
PasswordAuthentication no ChallengeResponseAuthentication no的方式來禁止密碼登錄。
關(guān)鍵字:服務(wù)器、源碼編譯
新文章:
- CentOS7下圖形配置網(wǎng)絡(luò)的方法
- CentOS 7如何添加刪除用戶
- 如何解決centos7雙系統(tǒng)后丟失windows啟動(dòng)項(xiàng)
- CentOS單網(wǎng)卡如何批量添加不同IP段
- CentOS下iconv命令的介紹
- Centos7 SSH密鑰登陸及密碼密鑰雙重驗(yàn)證詳解
- CentOS 7.1添加刪除用戶的方法
- CentOS查找/掃描局域網(wǎng)打印機(jī)IP講解
- CentOS7使用hostapd實(shí)現(xiàn)無AP模式的詳解
- su命令不能切換root的解決方法
- 解決VMware下CentOS7網(wǎng)絡(luò)重啟出錯(cuò)
- 解決Centos7雙系統(tǒng)后丟失windows啟動(dòng)項(xiàng)
- CentOS下如何避免文件覆蓋
- CentOS7和CentOS6系統(tǒng)有什么不同呢
- Centos 6.6默認(rèn)iptable規(guī)則詳解