升级ssh到最新版本

参考文章:

ssh对ssl是具有依赖关系的,需要检查这两者目前的版本

检查ssh的版本:

ssh -V

检查ssl版本:

openssl version

执行情况:

在这里插入图片描述

在openssh-8.4p1的INSTALL文件有ssh和ssl版本对应关系,以8.4的为例:

libcrypto from either of LibreSSL or OpenSSL.  Building without libcrypto
is supported but severely restricts the available ciphers and algorithms.
 - LibreSSL (https://www.libressl.org/)
 - OpenSSL (https://www.openssl.org) with any of the following versions:
   - 1.0.x >= 1.0.1 or 1.1.0 >= 1.1.0g or any 1.1.1

经过分析,我们并不需要升级ssl,只需要升级ssh,所以本文只升级ssh

注意:贸然升级ssl是不可行的,可能会导致已安装的应用依赖ssl不可用,具体参考链接2给出了如何正确升级ssl,然后升级ssh。

升级SSH

1、开启telnet访问

为了防止升级过程中通过ssh连接不到服务器,所以有必要留一条备用的连接方式。

升级方式文章1已做讲述,不再赘述

但是注意的是

1、开启telnet服务之后,可以使用ssh的用户名和密码进行telnet登录连接测试

2、关闭telnet服务器的防火墙,否则连不上

2、升级ssh

1、下载ssh相应的安装包

2、升级需要几个组件,有些是和编译相关的等

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

3、解压ssh安装包

[root@host-10-253-208-131 tools]# tar xfz openssh-8.4p1.tar.gz

4、给文件夹授予root权限

[root@host-10-253-208-131 tools]# chown -R root.root /data/tools/openssh-8.4p1

5、将之前的ssh目录备份,然后新建一个ssh目录

mv /etc/ssh /etc/ssh.old
mkdir /etc/ssh

6、进入openssh-8.4p1,检查、编译、安装

[root@host-10-253-208-131 tools]#  cd openssh-8.4p1
[root@host-10-253-208-131 openssh-8.4p1]# ./configure --prefix=/usr/ --sysconfdir=/etc/ssh   --with-zlib   --with-md5-passwords   --with-pam  && make && make install

# 检查是否安装成功,输出0成功
[root@host-10-253-208-131 openssh-8.4p1]# echo $?
0

如果openssl是通过编译安装的,那么它的安装位置应该不在默认的位置,所以在安装openssh时需要指定openssl的安装位置:

./configure --prefix=/usr/ --sysconfdir=/etc/ssh  --with-openssl-includes=/usr/local/openssl/include  --with-ssl-dir=/usr/local/openssl   --with-zlib   --with-md5-passwords   --with-pam  && make && make install

7、修改配置文件的内容为

[root@linux-node3 ~]# grep "^PermitRootLogin"  /etc/ssh/sshd_config
PermitRootLogin yes
[root@linux-node3 ~]# grep  "UseDNS"  /etc/ssh/sshd_config
UseDNS no
[root@linux-node3 ~]#

这里是指/etc/ssh/sshd_config这个文件的内容配置确保正确,如果不是的话需要进行修改来和上面执行的结果保持一致

8、对ssh服务进行一些配置

# 如果存在则覆盖
[root@host-10-253-208-131 openssh-8.4p1]# cp -af contrib/redhat/sshd.init /etc/init.d/sshd
[root@host-10-253-208-131 openssh-8.4p1]# cp -a contrib/redhat/sshd.pam /etc/pam.d/sshd.pam
[root@host-10-253-208-131 openssh-8.4p1]# chmod +x /etc/init.d/sshd
[root@host-10-253-208-131 openssh-8.4p1]# chkconfig --add sshd
[root@host-10-253-208-131 openssh-8.4p1]# systemctl enable sshd
sshd.service is not a native service, redirecting to /sbin/chkconfig.
Executing /sbin/chkconfig sshd on

# 把原先的systemd管理的sshd文件删除或者移走或者删除,不移走的话影响我们重启sshd服务,没有的话就不用管
[root@linux-node3 ~]# mv  /usr/lib/systemd/system/sshd.service  /data/
#设置sshd服务开机启动
[root@linux-node3 ~]# chkconfig sshd on

9、测试服务的启停

# 启动
    /etc/init.d/sshd start
或
systemctl start sshd
# 关闭
/etc/init.d/sshd stop
或
systemctl stop sshd
# 重启
/etc/init.d/sshd restart
或
/etc/init.d/sshd start

10、查看ssh的版本,使用ssh工具测试连接是否正常,没问题关闭telnet服务

# 查看ssh的版本
ssh -V
# 关闭telnet
[root@host-10-253-208-131 ~]#  systemctl disable xinetd.service
Removed symlink /etc/systemd/system/multi-user.target.wants/xinetd.service.
[root@host-10-253-208-131 ~]# systemctl stop xinetd.service
[root@host-10-253-208-131 ~]# systemctl disable telnet.socket
Removed symlink /etc/systemd/system/sockets.target.wants/telnet.socket.
[root@host-10-253-208-131 ~]# systemctl stop telnet.socket
[root@host-10-253-208-131 ~]#  netstat -lntp
  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值