记centos7升级openssh

记centos7升级openssh

April 144 2023-03-20

低版本的危害

丫丫的,一下午修了8台服务器的openssh。。。
纯属当工作笔记了。

OpenSSH(OpenBSD Secure Shell)是OpenBSD计划组所维护的一套用于安全访问远程计算机的连接工具。该工具是SSH协议的开源实现,支持对所有的传输进行加密,可有效阻止窃听、连接劫持以及其他网络级的攻击。

OpenSSH 7.7及之前版本中存在用户枚举漏洞,该漏洞源于程序会对有效的和无效的用户身份验证请求发出不同的响应。攻击者可通过发送特制的请求利用该漏洞枚举用户名称。

新版本OpenSSH-7.8已经修复这个安全问题

更新

先看看有没有新版本,反正官方给的一定不会错。

yum update openssh -y
ssh -V

编译前准备

yum install  -y gcc gcc-c++ glibc make autoconf openssl openssl-devel pcre-devel  pam-devel

编译安装openssl

# 下载数据包,官方下载的也可以,我只不过是放到了我自己的文件源中
wget https://www.openssl.org/source/openssl-1.1.1q.tar.gz --no-check-certificate

tar xf openssl-1.1.1q.tar.gz

# 备份原来的openssl
mv /usr/bin/openssl{,.bak}
mv /usr/include/openssl{,.bak}

cd openssl-1.1.1q
# 编译安装
./config shared && make && make install
# 创建软连接
ln -s /usr/local/bin/openssl /usr/bin/openssl
ln -s /usr/local/include/openssl/ /usr/include/openssl
echo "/usr/local/lib64" >> /etc/ld.so.conf
/sbin/ldconfig
openssl version

image-1679305722931
openssl version 版本1.1.1d, 即更新成功!

编译安装openssh

中间ssh是不会断的!

# 下载更新包
wget https://www.aprilming.top/file/linux/openssh/openssh-9.1p1.tar.gz --no-check-certificate
tar xf openssh-9.1p1.tar.gz

# 备份ssh
mv /etc/ssh{,.bak}

cd openssh-9.1p1
mkdir /usr/local/openssh

# 预编译
./configure --prefix=/usr/local/openssh --sysconfdir=/etc/ssh --with-openssl-includes=/usr/local/include --with-ssl-dir=/usr/local/lib64 --with-zlib --with-md5-passwords
# 如果上面的预编译失败,请使用下面的这个命令
./configure --prefix=/usr/local/openssh --sysconfdir=/etc/ssh --with-openssl-includes=/usr/local/include --with-ssl-dir=/usr/bin/openssl --with-zlib --with-md5-passwords
# 编译安装
make && make install
#  添加ssh配置
echo "UseDNS no" >> /etc/ssh/sshd_config
echo 'PermitRootLogin no' >> /etc/ssh/sshd_config
echo 'PubkeyAuthentication yes' >> /etc/ssh/sshd_config
echo 'PasswordAuthentication yes' >> /etc/ssh/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
# 替换二进制文件
mv /usr/sbin/sshd{,.bak}
mv /usr/bin/ssh{,.bak}
mv /usr/bin/ssh-keygen{,.bak}
#  创建链接
ln -s /usr/local/openssh/bin/ssh /usr/bin/ssh
ln -s /usr/local/openssh/bin/ssh-keygen /usr/bin/ssh-keygen
ln -s /usr/local/openssh/sbin/sshd /usr/sbin/sshd
#  验证版本
ssh -V
#  更新sshd的启动脚本
mv /usr/lib/systemd/system/sshd.service{,.bak}
## contrib在openssh源码包解压后的目录
cp -a ./contrib/redhat/sshd.init /etc/init.d/sshd
cp -a ./contrib/redhat/sshd.pam /etc/pam.d/sshd.pam
chkconfig --add sshd
systemctl enable sshd --now
systemctl restart sshd

ssh连接

测试一下ssh连接是否正常吧。

脚本

openssl:
https://www.aprilming.top/file/script/update_openssl.sh
openssh:
https://www.aprilming.top/file/script/update_openssh.sh

不要无脑执行!