Update-SSH

本文档详细介绍了在CentOS系统上如何升级OpenSSL和SSH的过程,包括前期的系统更新、依赖包安装,然后是解压安装OpenSSL,备份原有文件,编译并设置软链接,最后是安装SSH,配置文件,删除旧的sshd服务,设置自启动,并测试新安装的服务。整个过程旨在确保系统的安全性和稳定性。
摘要由CSDN通过智能技术生成

一、前期准备:

备注:
如果ssh版本过低,最好先yum update openssh升级下到目前yum仓库默认的openssh7.4p1版本,减少各依赖组件的版本过低引起不必要问题。

[root@localhost ~]# yum update openssh -y
[root@localhost ~]# ssh -V
OpenSSH_7.4p1, OpenSSL 1.0.2k-fips  26 Jan 2017

1)、安装telnet-server以及xinetd

[root@localhost ~]# yum install xinetd telnet-server -y

查看网上文档,安装telnet-server以及xinetd之后有一个telnet的配置文件,实际操作中,并没有该文件,

[root@localhost ~]# ll /etc/xinetd.d/telnet
ls: cannot access /etc/xinetd.d/telnet: No such file or directory

再此跳过~

2)、配置telnet登录的终端类型,在/etc/securetty文件末尾增加一些pts终端,如下

[root@localhost ~]# vi /etc/services
[root@localhost ~]# tail -n5 /etc/securetty 
xvc0
pts/0
pts/1
pts/2

3)、启动telnet服务,并设置开机自动启动

[root@localhost ~]# systemctl enable xinetd
[root@localhost ~]# systemctl enable telnet.socket
[root@localhost ~]# 
[root@localhost ~]# systemctl start telnet.socket
[root@localhost ~]# 
[root@localhost ~]#  systemctl start xinetd
[root@localhost ~]# 
[root@localhost ~]# netstat -lntp|grep 23
tcp        0      0 0.0.0.0:22            0.0.0.0:*            LISTEN      19233/sshd  
tcp6       0      0 :::22                 :::*                 LISTEN      19233/sshd          
tcp6       0      0 :::23                 :::*                 LISTEN      1/systemd

4)、切换到telnet方式登录,以后的操作都在telnet终端下操作,防止ssh连接意外中断造成升级失败

telnet登录:
image.png

安装依赖包:

升级需要几个组件,有些是和编译相关的
[root@localhost ~]# yum install -y gcc gcc-c++ glibc make autoconf openssl openssl-devel pcre-devel pam-devel

备注:亲测中没有安装依赖,也可以成功。

二、安装openssl

ssh下载路径:
https://openbsd.hk/pub/OpenBSD/OpenSSH/portable/
ssl下载路径:
https://ftp.openssl.org/source/

1、上传离线包到/usre/local/src/下,并进行解包。

image.png

2、执行下面两个命令对原有文件备份

mv /usr/bin/openssl /usr/bin/openssl_bak
mv /usr/include/openssl /usr/include/openssl_bak

3、编译安装新版本的openssl

进入解包的openssl文件,执行配置&编译&安装命令

./config shared && make && make install

以上命令执行完毕,使用echo $?查看下最后的make install是否有报错,0表示没有问题
image.png

4、目录做软链接,依次执行如下命名。

ln -s /usr/local/ssl/bin/openssl /usr/bin/openssl
ln -s /usr/local/ssl/include/openssl /usr/include/openssl	
ll /usr/bin/openssl
ll /usr/include/openssl -ld

5、加载配置

echo "/usr/local/ssl/lib" >> /etc/ld.so.conf
/sbin/ldconfig

查看新安装的版本,到此安装ssl完成。

openssl version

image.png

三、安装ssh

1、解包openssh,并进入目录

image.png

更改属主:

chown -R root:root openssh-8.3p1

2、删除原先ssh的配置文件和目录

rm -rf /etc/ssh/*          #安全起见:可备份到其他地方

3、配置$编译&安装

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

执行完后,检查安装是否正常。

echo $?

4、修改配文件;/etc/ssh/sshd_config

image.png

去掉#,no 改成yes。#root用户可直接登录。

5、拷贝一些文件到目标位置

(在此不过的解释,依次执行命令)

cp -a contrib/redhat/sshd.init /etc/init.d/sshd
cp -a contrib/redhat/sshd.pam /etc/pam.d/sshd.pam
chmod +x /etc/init.d/sshd
chkconfig --add sshd
systemctl enable sshd

6、把原先的systemd管理的sshd文件删除或者移走或者删除,不移走的话影响我们重启sshd服务

 mv  /usr/lib/systemd/system/sshd.service  /data/

7、设置开机自启

chkconfig sshd on

启动服务&检查版本:
image.png

8、为了安装可自定义修改sshd服务开启端口

image.png

9、新建终端,测试sshd服务,正常后,关闭telnet远程登录。

systemctl disable xinetd.service
systemctl stop xinetd.service
systemctl disable telnet.socket
systemctl stop telnet.socket

最后确认telnet端口关闭,
netstat -lntp

到此ssh升级完成。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值