目标环境
- CentOS 6.10 x86_x64
- OpenSSL 1.0.1e --> 1.1.1g
- OpenSSH 5.3p1 --> 8.2p1
背景
为了让 Web 服务器支持新特性 TLS v1.3 与 HTTP/2,同时避免老版本 OpenSSH 的各种安全漏洞。
升级 OpenSSL
yum install -y gcc perl zlib-devel
查看版本 openssl version
OpenSSL 1.0.1e
下载
从官网 https://www.openssl.org/source 下载源码
wget https://www.openssl.org/source/openssl-1.1.1g.tar.gz
tar zxvf openssl-1.1.1g.tar.gz
编译、安装
cd openssl-1.1.1g
./config --prefix=/usr/local/ssl-1.1.1g enable-tls1_3 shared zlib-dynamic
make && make install
备份
mv /usr/bin/openssl /usr/bin/openssl.bak
// 如果存在的话
mv /usr/include/openssl /usr/include/openssl.bak
建立软链接
ln -s /usr/local/ssl-1.1.1g/bin/openssl /usr/bin/openssl
ln -s /usr/local/ssl-1.1.1g/include/openssl /usr/include/openssl
ln -s /usr/local/ssl-1.1.1g/lib/libssl.so.1.1 /usr/lib64/libssl.so
echo "/usr/local/ssl-1.1.1g/lib" >> /etc/ld.so.conf
ldconfig -v
验证
openssl version
OpenSSL 1.1.1g
openssl s_client --help
-tls1_3 Just use TLSv1.3
升级 OpenSSH
旧版本的 OpenSSH 存在严重的安全漏洞,所以要升级到最新。yum install -y gcc pam-devel zlib-devel
安装 telnet
安装 telnet 服务端 yum install -y telnet-server
配置 telnet 服务端 vi /etc/xinetd.d/telnet
disable = no
mv /etc/securetty /etc/securetty.bak
service xinetd start
chkconfig xinetd on
退出 ssh 会话,使用 telnet 客户端登陆服务器。(注意在防火墙中放行 TCP/23 端口)
查看版本 sshd -V
OpenSSH_5.3p1
备份
cp /etc/ssh /etc/ssh.bak
cp /etc/init.d/sshd /etc/init.d/sshd.bak
卸载
rpm -qa | grep openssh
openssh-5.3p1-124.el6_10.x86_64
openssh-server-5.3p1-124.el6_10.x86_64
openssh-clients-5.3p1-124.el6_10.x86_64
rpm -e --nodeps openssh-5.3p1-124.el6_10.x86_64
rpm -e --nodeps openssh-server-5.3p1-124.el6_10.x86_64
rpm -e --nodeps openssh-clients-5.3p1-124.el6_10.x86_64
如果卸载 openssh server 时提示错误
error reading information on service sshd: No such file or directory
error: %preun(openssh-server-5.3p1-104.el6.x86_64) scriptlet failed, exit status 1
使用指令 rpm -e --noscripts openssh-server-5.3p1-124.el6_10.x86_64
再确认一下 rpm -qa | grep openssh
准备目录
install -v -m700 -d /var/lib/sshd
chown -v root:sys /var/lib/sshd
cut -d : -f 1 /etc/passwd
// 如存在用户 sshd 则无需操作
// groupadd -g 50 sshd
// useradd -c 'sshd PrivSep' -d /var/lib/sshd -g sshd -s /bin/false -u 50 sshd
编译、安装
访问 https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/ 下载源码
wget https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-8.2p1.tar.gz
tar zxvf openssh-8.2p1.tar.gz
cd openssh-8.2p1
./configure --prefix=/usr --sysconfdir=/etc/ssh --with-md5-passwords --with-pam --with-zlib --with-openssl-includes=/usr/local/ssl-1.1.1g/include --with-ssl-dir=/usr/local/ssl-1.1.1g --with-privsep-path=/var/lib/sshd
make && make install
验证
sshd -V
OpenSSH_8.2p1, OpenSSL 1.1.1g
配置
install -v -m755 contrib/ssh-copy-id /usr/bin
install -v -m644 contrib/ssh-copy-id.1 /usr/share/man/man1
install -v -m755 -d /usr/share/doc/openssh-8.2p1
install -v -m644 INSTALL LICENCE OVERVIEW README* /usr/share/doc/openssh-8.2p1
cp sshd_config /etc/ssh/sshd_config
echo "PasswordAuthentication yes" >> /etc/ssh/sshd_config
echo "PermitRootLogin yes" >> /etc/ssh/sshd_config
echo "X11Forwarding yes" >> /etc/ssh/sshd_config
cp -p ./contrib/redhat/sshd.init /etc/init.d/sshd
chmod +x /etc/init.d/sshd
chkconfig --add sshd
chkconfig sshd on
启动服务 service sshd start
断开 telnet 会话,通过 ssh 登陆服务器。
卸载 telnet
mv /etc/securetty.bak /etc/securetty
chkconfig xinetd off
service xinetd stop
yum remove -y telnet-server
最后关闭防火墙中开放的 telnet 端口。
版权声明:本文为原创文章,版权归 BenhoN 所有。
本文链接:https://blog.benhon.net/archives/upgrade_openssl_openssh_on_centos_6.html
所有原创文章采用知识共享 署名-非商业性使用 4.0 国际 许可协议进行许可,你可以自由地转载和修改,但请务必注明文章来源并且不可用于商业目的。