************本文檔適用於CentOS7.x從openssh7.4p1升級到openssh8.4p1************
1、升級准備工作
1.1、查看系統版本和ssh版本
cat /etc/redhat-release
ssh -V
1.2、需要將openssh升級到最新版本
直接yum安裝即可
yum install openssh -y
可以看已經升級到7.4p1了,下面將從openssh7.4p1升級到openssh8.4p1
1.3、安裝需要的依賴包
yum -y install gcc gcc-c++ kernel-devel
2、安裝包准備
2.1、下載安裝包
zlib-1.2.11.tar.gz 下載地址:http://www.zlib.net/zlib-1.2.11.tar.gz 也可以直接下載:wget http://www.zlib.net/zlib-1.2.11.tar.gz
openssl-1.1.1h.tar.gz 下載地址:https://www.openssl.org/source/openssl-1.1.1h.tar.gz 也可以直接下載:wget https://www.openssl.org/source/openssl-1.1.1h.tar.gz
openssh-8.4p1.tar.gz 下載地址:http://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-8.4p1.tar.gz 也可以直接下載:wget http://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-8.4p1.tar.gz
查看安裝包:
2.2、解壓安裝包,我習慣將安裝包解壓到/usr/local/src下面
tar xf openssh-8.4p1.tar.gz -C /usr/local/src/ tar xf openssl-1.1.1h.tar.gz -C /usr/local/src/ tar xf zlib-1.2.11.tar.gz -C /usr/local/src/ ll /usr/local/src/
3、安裝
3.1、安裝zlib-1.2.11.tar.gz
[root@test3 ~]# cd /usr/local/src/zlib-1.2.11/ [root@test3 zlib-1.2.11]# ./configure --prefix=/usr/local/zlib && make -j 4 && make install
3.2、安裝 openssl-1.1.1h.tar.gz
[root@test3 zlib-1.2.11]# cd /usr/local/src/openssl-1.1.1h/
[root@test3 openssl-1.1.1h]# ./config --prefix=/usr/local/ssl -d shared
[root@test3 openssl-1.1.1h]# make -j 4 && make install
[root@test3 openssl-1.1.1h]# echo '/usr/local/ssl/lib' >> /etc/ld.so.conf
[root@test3 openssl-1.1.1h]# ldconfig -v
3.3、安裝openssh-8.4p1.tar.gz
mv /etc/ssh /etc/ssh.bak
cd /usr/local/src/openssh-8.4p1/ ./configure --prefix=/usr/local/openssh --sysconfdir=/etc/ssh --with-ssl-dir=/usr/local/ssl --with-zlib=/usr/local/zlib
make -j 4 && make install
sshd_config文件修改
echo "X11Forwarding yes" >> /etc/ssh/sshd_config echo "X11UseLocalhost no" >> /etc/ssh/sshd_config echo "XAuthLocation /usr/bin/xauth" >> /etc/ssh/sshd_config echo "UseDNS no" >> /etc/ssh/sshd_config echo 'PermitRootLogin yes' >> /etc/ssh/sshd_config echo 'PubkeyAuthentication yes' >> /etc/ssh/sshd_config echo 'PasswordAuthentication yes' >> /etc/ssh/sshd_config
echo 'KexAlgorithms curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group14-sha1' >> /etc/ssh/sshd_config
需要添加X11Forwarding yes開啟X11轉發,調用圖形界面,如oracle安裝等操作需要圖形界面
***必須添加X11UseLocalhost no 和 XAuthLocation /usr/bin/xauth 這兩項,否則X11轉發不好使
驗證X11轉發是否好使,xhost + 出現下面的是可以正常使用的
出現下面的內容是不能正常使用的
備份 /etc/ssh 原有文件,並將新的配置復制到指定目錄
mv /usr/sbin/sshd /usr/sbin/sshd.bak cp -rf /usr/local/openssh/sbin/sshd /usr/sbin/sshd mv /usr/bin/ssh /usr/bin/ssh.bak cp -rf /usr/local/openssh/bin/ssh /usr/bin/ssh mv /usr/bin/ssh-keygen /usr/bin/ssh-keygen.bak cp -rf /usr/local/openssh/bin/ssh-keygen /usr/bin/ssh-keygen
查看版本ssh -V
4、啟動sshd
直接systemctl start sshd,啟動不起來,報錯,但用sshd -t檢查也沒有啥錯誤,就提示timeout
問題解決:先停掉sshd服務,將systemctl原服務器刪除,使用安裝包里自帶的sshd.init,復制到/etc/init.d/sshd,重啟即可
systemctl stop sshd.service
rm -rf /lib/systemd/system/sshd.service systemctl daemon-reload cp /usr/local/src/openssh-8.4p1/contrib/redhat/sshd.init /etc/init.d/sshd /etc/init.d/sshd restart systemctl status sshd
啟動不起來,可以使用/etc/init.d/sshd restart重啟即可
添加開機啟動
chkconfig --add sshd
chkconfig --list sshd
5、為了防止升級失敗,可以在升級之前安裝telnet服務,通過Telnet連接服務器進行升級
5.1、安裝telnet-server以及xinetd
yum install xinetd telnet-server -y
vim /etc/xinetd.d/telnet
service telnet { disable = yes flags = REUSE socket_type = stream wait = no user = root server = /usr/sbin/in.telnetd log_on_failure += USERID }
配置telnet登錄的終端類型,在/etc/securetty文件末尾增加一些pts終端,如下
vim /etc/securetty
pts/0 pts/1 pts/2 pts/3
tail -5 /etc/securetty
xvc0 pts/0 pts/1 pts/2 pts/3
systemctl enable xinetd
systemctl enable telnet.socket
systemctl start telnet.socket
systemctl start xinetd
netstat -lntp|grep 23
netstat可能會報錯,原因是沒有安裝net-tools工具包
yum install net-tools -y
再次查看
切換到telnet方式登錄,以后的操作都在telnet終端下操作,防止ssh連接意外中斷造成升級失敗
5.2、刪除Telnet服務
systemctl disable xinetd.service
systemctl stop xinetd.service
systemctl disable telnet.socket
systemctl stop telnet.socket
netstat -lntp
卸載yum remove telnet-server xinetd -y