因为系统漏洞,安全加固等各种原因会经常升级openssl、openssh组件。

openssl下载网站:https://www.openssl.org/source/

openssh下载网站:https://mirrors.aliyun.com/pub/OpenBSD/OpenSSH/portable/

安装telnet服务

因为升级openssh会修改和重启ssh服务,防止升级失败导致ssh不可用,要先安装telnet服务。或者机器有vnc也可以直接跳过该步骤。

  1. 使用YUM安装telnet以及依赖包。

[root@heiying ~]# yum -y install telnet telnet-server xinetd gcc vim wget [root@heiying ~]# iptables -F [root@heiying ~]# setenforce 0

  1. 启动telnet

[root@heiying ~]# systemctl start telnet.socket ## 注释remote文件,第一行;永许使用root登录 [root@heiying ~]# vim /etc/pam.d/remote #auth required pam_securetty.so

  1. 安装xinetd服务。

[root@heiying ~]# vim /etc/xinetd.d/telnet service telnet { flags = REUSE socket_type = stream wait = no user = root server = /usr/sbin/in.telnetd log_on_failure = USERID disable = no } [root@heiying ~]# systemctl start xinetd.service

  1. 测试登录telnet

在linux系统查看openssl版本(Centos7升级opensslopenssh)(1)

升级openssl
  1. 查看现有版本

[root@heiying ~]# openssl version

在linux系统查看openssl版本(Centos7升级opensslopenssh)(2)

  1. 安装新版本openssl

## 编译安装openssl [root@heiying ~]# tar xf openssl-1.1.1l.tar.gz [root@heiying ~]# cd openssl-1.1.1l [root@heiying openssl-1.1.1l]# ./config --prefix=/usr/local/openssl [root@heiying openssl-1.1.1l]# make -j4 && make install ## 备份旧openssl [root@heiying ~]# mv /usr/bin/openssl{,.old} ## 使用新openssl [root@heiying ~]# ln -sf /usr/local/openssl/bin/openssl /usr/bin/openssl [root@heiying ~]# echo "/usr/local/openssl/lib" >> /etc/ld.so.conf [root@heiying ~]# ldconfig -v

  1. 检测是否生效

[root@heiying ~]# openssl version

在linux系统查看openssl版本(Centos7升级opensslopenssh)(3)

升级openssh
  1. 安装依赖并备份旧环境

[root@heiying ~]# yum -y install gcc zlib zlib-devel openssl-devel pam pam-devel ## 备份旧ssh [root@heiying ~]# mv /etc/ssh{,.old} [root@heiying ~]# rm -f /bin/ssh* [root@heiying ~]# rm -f /etc/pam.d/sshd [root@heiying ~]# mv /sbin/sshd{,.old} [root@heiying ~]# mv /sbin/sshd-keygen{,.old}

  1. 编译安装openssh

[root@heiying ~]# tar xf openssh-8.3p1.tar.gz [root@heiying ~]# cd openssh-8.3p1 [root@heiying openssh-8.3p1]# ./configure \ --prefix=/usr/local/openssh \ --sysconfdir=/etc/ssh \ --with-pam \ --with-ssl-dir=/usr/local/openssl \ --with-md5-passwords \ --mandir=/usr/share/man \ --with-zlib \ --without-hardening [root@heiying openssh-8.3p1]# make -j4 && make install [root@heiying openssh-8.3p1]# cp contrib/redhat/sshd.init /etc/init.d/sshd [root@heiying openssh-8.3p1]# cp contrib/redhat/sshd.pam /etc/pam.d/ [root@heiying ~]# ln -sf /usr/local/openssh/bin/ssh-keygen /usr/bin/ssh-keygen [root@heiying ~]# chmod x /etc/init.d/sshd [root@heiying ~]# chkconfig --add sshd [root@heiying ~]# chkconfig sshd on ## 修改新的sshd路径 [root@heiying ~]# vim /etc/init.d/sshd SSHD=/usr/local/openssh/sbin/sshd [root@heiying ~]# sed -i 's/#PermitRootLogin.*/PermitRootLogin yes/' /etc/ssh/sshd_config [root@heiying ~]# sed -i 's/#ListenAddress 0.0.0.0/ListenAddress 0.0.0.0/' /etc/ssh/sshd_config ## 添加环境变量 [root@heiying ~]# vim /etc/profile export PATH=$PATH:/usr/local/openssh/bin [root@heiying ~]# . /etc/profile

  1. 重启SSH服务

[root@heiying ~]# systemctl stop sshd.service [root@heiying ~]# rm -f /usr/lib/systemd/system/sshd.service [root@heiying ~]# systemctl daemon-reload [root@heiying ~]# /etc/init.d/sshd restart

  1. 关闭telnet服务

telnet服务相对ssh安全性较低,一把不使用telnet作为远程工具,所以此处要关闭。

[root@heiying ~]# systemctl stop telnet.socket [root@heiying ~]# rm -f /etc/xinetd.d/telnet [root@heiying ~]# systemctl stop xinetd.service

测试

在linux系统查看openssl版本(Centos7升级opensslopenssh)(4)

,