Centos7 升级OpenSSH9.0版本解决CVE-2021-41617漏洞
准备(必备)
centos安装telnet-server,默认启动23端口,通过telnet客户端可以连接telent-server服务器,正常执行linux的操作,但是因为telnet在网络上是通过明文传输的,不安全,所以升级完ssh之后需要重新关闭telnet-server服务。
安装telnet
yum install -y telnet-server xinetd
telnet-server托管于linux的超级进程xinetd,配置xinetd,执行:vi /etc/xinetd.d/telnet
如果文件不存在的话则新建文件,如果文件存在,检查disable
参数是否设置为no
,如果是yes
,则改为no
service telnet
{
flags = REUSE
socket_type = stream
wait = no
user = root
server = /usr/sbin/in.telnetd
log_on_failure += USERID
disable = no
}
重启xinetd
service xinetd restart
#或者根据操作系统的版本不同
systemctl restart xinetd
查看telnet端口是否启动,看到23端口(默认)也有可能是其他端口 即正常启动
netstat -ntlp |grep xinetd
默认情况下,telnet不允许root远程登录,我们此处使用普通用户登录telnet,如果需要root权限,用普通用户登录 通过su root
切换至root即可
升级需要几个组件,有些是和编译相关的等
yum install -y gcc gcc-c++ glibc make autoconf openssl openssl-devel pcre-devel pam-devel
yum install -y pam* zlib*
下载源码文件包
手动去官网下载
wget https://mirror.leaseweb.com/pub/OpenBSD/OpenSSH/portable/openssh-9.0p1.tar.gz
wget https://www.openssl.org/source/openssl-1.1.1p.tar.gz
编译安装openssl
tar -zxf openssl-1.1.1p.tar.gz
cd openssl-1.1.1p
#编译安装
./config --prefix=/usr/local/openssl -d shared && make -j2 && make install
#mv备份过原来的
mv /usr/bin/openssl /usr/bin/openssl.bak
mv /usr/include/openssl /usr/include/openssl.bak
#目录软链接
ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl
ln -s /usr/local/openssl/include/openssl /usr/include/openssl
ln -s /usr/local/openssl/lib/libssl.so.1.1 /usr/local/lib64/libssl.so.1.1
ln -s /usr/local/openssl/lib/libcrypto.so.1.1 /usr/local/lib64/libcrypto.so.1.1
ln -s /usr/local/openssl/lib/libssl.so.1.1 /usr/lib64/libssl.so.1.1
ln -s /usr/local/openssl/lib/libcrypto.so.1.1 /usr/lib64/libcrypto.so.1.1
#命令行执行下面2个命令加载新配置
echo '/usr/local/openssl/lib' >> /etc/ld.so.conf
ldconfig -v
/sbin/ldconfig
#查看确认版本。没问题
[root@testssh ~]# openssl version
OpenSSL 1.1.1p 21 Jun 2022
编译安装openssh
tar -zxf openssh-9.0p1.tar.gz
chown -R root.root openssh-9.0p1
cd openssh-9.0p1
#编译安装
./configure --prefix=/usr/local/openssh --with-zlib --with-ssl-dir=/usr/local/openssl && make -j2&& make install
sshd_config文件修改
如果原来的sshd_config修改过很多参数,需要于原来的进行对比哦
echo 'PermitRootLogin yes' >>/usr/local/openssh/etc/sshd_config
echo 'PubkeyAuthentication yes' >>/usr/local/openssh/etc/sshd_config
echo 'PasswordAuthentication 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/scp /usr/bin/scp.bak
cp /usr/local/openssh/bin/scp /usr/bin/scp
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
开机自启动&启动sshd
systemctl daemon-reload
service sshd restart
/etc/rc.d/init.d/sshd start #启动sshd
/etc/rc.d/init.d/sshd stop #停止sshd
#其他命令
systemctl enable sshd #开机自动启动
systemctl start sshd #启动sshd
systemctl status sshd #查看状态
systemctl restart sshd # 重新启动
关闭telent和端口23
systemctl disable xinetd.service
systemctl stop xinetd.service
systemctl disable telnet.socket
systemctl stop telnet.socket
ss -lntp