ubuntu离线升级ssh的方法
问题背景
使用的服务器在安全漏洞扫描中发现ssh存在高危漏洞,建议更新ssh到最新版本,因为开发环境服务器无法网络,故记录ubuntu离线升级ssh方法。
使用环境
ubuntu16.04
离线包下载
zlib
下载地址:http://www.zlib.net/
这里使用最新的1.2.12
openssl
下载地址:https://www.openssl.org/source/
这里使用1.1.1q
openssh
下载地址:http://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/
这里使用9.0p1
离线包安装
openssh离线升级时需要zlib和openssl依赖,所以需要先安装两个依赖。
zlib安装
tar -xzvf zlib-1.2.12.tar.gz
cd zlib-1.2.12
./configure --prefix=/usr/local/zlib
make && make install
openssl安装
tar -xzvf openssl-1.1.1q.tar.gz
cd openssl-1.1.1q
./config --prefix=/usr/local/ssl -d shared
make && make install
echo '/usr/local/ssl/lib' >> /etc/ld.so.conf
ldconfig -v
openssh安装
tar -xzvf openssh-9.0p1.tar.gz
cd openssh-9.0p1
./configure --prefix=/usr/local/openssh --with-zlib=/usr/local/zlib --with-ssl-dir=/usr/local/ssl
make && make install
修改ssh配置文件
#ssh 允许 root 用户登录
echo ‘PermitRootLogin yes’ >> /usr/local/openssh/etc/sshd_config
#ssh 允许使用密码登录
echo ‘PasswordAuthentication yes’ >> /usr/local/openssh/etc/sshd_config
#ssh 允许使用公钥登录
echo ‘PubkeyAuthentication yes’ >> /usr/local/openssh/etc/sshd_config
替换配置文件
mv /etc/ssh/sshd_config /etc/ssh/sshd_config.bak
cp /usr/local/openssh/etc/sshd_config /etc/ssh/sshd_config
mv /usr/sbin/sshd /usr/sbin/sshd.bak
cp /usr/local/openssh/sbin/sshd /usr/sbin/sshd
mv /usr/bin/ssh /usr/bin/ssh.bak
cp /usr/local/openssh/bin/ssh /usr/bin/ssh
mv /usr/bin/ssh-keygen /usr/bin/ssh-keygen.bak
cp /usr/local/openssh/bin/ssh-keygen /usr/bin/ssh-keygen
mv /etc/ssh/ssh_host_ecdsa_key.pub /etc/ssh/ssh_host_ecdsa_key.pub.bak
cp /usr/local/openssh/etc/ssh_host_ecdsa_key.pub /etc/ssh/ssh_host_ecdsa_key.pub
重启ssh
重启ssh:systemctl restart sshd
查看版本:ssh -V
查看运行状态:sudo ps -e | grep ssh