准备工作
- 升级ssh可能会造成服务器无法连接,如果不能直接操作服务器,请开启telnet或者vnc
- 查看openssl版本,openssl version,在这里下载1.0.2版本 https://www.openssl.org/source/
- 查看openssh版本,ssh -V,在这里下载新版本8.0p1 https://www.openssh.com/portable.html
- 安装pam和zlib
升级openssl
- 备份原来的openssl
mv /usr/bin/openssl /usr/bin/openssl.bak
mv /usr/include/openssl /usr/include/openssl.bak
- 使用命令编译安装
./config shared
make
make install
ln -s /usr/local/ssl/bin/openssl /usr/bin/openssl
ln -s /usr/local/ssl/include/openssl /usr/include/openssl
- 加载动态库
echo "/usr/local/ssl/lib" >> /etc/ld.so.conf
ldconfig
- 确认版本
升级openssh
- 备份原来的ssh和配置文件
mv /etc/ssh /etc/ssh.bak
mv /usr/bin/ssh /usr/bin/ssh.bak
mv /etc/init.d/sshd /etc/init.d/sshd.bak
- 编译安装
./configure --prefix=/usr/ --sysconfdir=/etc/ssh --with-openssl-includes=/usr/local/ssl/include --with-ssl-dir=/usr/local/ssl --with-zlib --with-md5-passwords --with-pam
# 如果出现pam错误,需要安装 yum -y install pam-devel
make
make install
- 重新配置ssh
cp contrib/redhat/sshd.init /etc/init.d/sshd
chmod +x /etc/init.d/sshd
chkconfig --add sshd
chkconfig sshd on
修改/etc/ssh/sshd_config
PermitRootLogin yes
UseDNS no
如果还有其他配置,从备份的config里copy
- 确认版本,重启
service sshd restart
参考资料