Centos7 升级至openssh-9.8p1

1. 升级前准备:安装telnet,防止升级失败后不能登录。
#1. 检查相关依赖包是否安装
rpm -qa | egrep "xinetd|telnet|telnet-server"
#安装所缺的依赖包
rpm -ivh xinetd-2.3.15-14.el7.x86_64.rpm telnet-server-0.17-65.el7_8.x86_64.rpm

#2. 允许root用户通过telnet登陆
#编辑/etc/pam.d/login,注释掉下面这行
vi /etc/pam.d/login
#auth [user_unknown=ignore success=ok ignore=ignore default=bad]
pam_securetty.so

#3. 备份/etc/securetty文件:
cp /etc/securetty /etc/securetty.bak

#4. 配置/etc/securetty
vi /etc/pam.d/login
#添加如下内容
pts/0
pts/1
pts/2
pts/3
pts/4
pts/5

#5. 开启root用户远程登陆
#编辑/etc/pam.d/remote,注释下列这行:
vi /etc/pam.d/remote
#auth required pam_securetty.so

#6. 重启telnet和xinetd服务【telnet服务依赖于xinetd服务】
systemctl start telnet.socket
systemctl start xinetd
#PS:如果开启了防火墙,需要将23端口(系统默认23为telnet端口)添加到防火墙允许的端口的列表中。

#7. 开启telnet和xinetd开机自动启动
#systemctl enable xinetd.service
#systemctl enable telnet.socket
#关闭telnet和xinetd开机自启动
#systemctl disable xinetd.service
#systemctl disable telnet.socket

#8. 验证开机启动
#systemctl list-unit-files |grep telnet
#systemctl list-unit-files |grep xinetd

#9. 连接验证
telnet xxx.xxx.xx.xx
#添加防火墙规则
firewall-cmd --add-port=23/tcp --permanent #开放23端口
success
firewall-cmd --reload #使配置生效
success
firewall-cmd --query-port=23/tcp #查询23端口是否开启成
yes
#升级完关闭23端口
firewall-cmd --permanent --remove-port=23/tcp
firewall-cmd --reload
#停服务
systemctl stop telnet.socket
systemctl stop xinetd
#还原上述2、3、4、5步骤的修改
2. 升级openssl
#1. 解压
tar -zxvf openssl-3.3.1.tar.gz

#2. 安装openssl
cd openssl-3.3.1
./config --prefix=/usr/ --openssldir=/usr/ shared
make && make install

#3. 备份原来的openssl
mv /usr/bin/openssl /usr/bin/openssl.bak
mv /usr/include/openssl /usr/include/openssl.bak
mv /usr/lib64/openssl /usr/lib64/openssl.bak
mv /usr/lib64/libssl.so /usr/lib64/libssl.so.bak

#4. 配置链接新版本
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 /usr/lib64/libssl.so
# 编辑新配置文件ssl.conf或修改/etc/ld.so.conf文件
#-----(1)编辑新配置文件ssl.conf-------
vi /etc/ld.so.conf.d/ssl.conf
#加入如下内容后保存退出
/usr/local/openssl/lib
#-----(2)修改/etc/ld.so.conf文件-------
echo "/usr/local/openssl/lib" >> /etc/ld.so.conf

#5. 刷新库文件
ldconfig -v

#6. 检查当前系统 openssl 版本
openssl version
3. 升级openssh
#1. 解压
tar -zxvf openssh-9.8p1.tar.gz

#2. 安装
cd openssh-9.8p1
./configure --prefix=/usr/local/openssh --sysconfdir=/etc/ssh --with-pam --with-ssl-dir=/usr/  --with-md5-passwords --mandir=/usr/share/man --with-zlib=/usr/local/zlib --without-hardening
make && make install

#3. 验证openssh版本
/usr/local/openssh/bin/ssh -V

#4. 设置sshd服务开机自动启动
#备份配置文件
mv /etc/init.d/sshd /etc/init.d/sshd.bak
#替换配置文件
cp /usr/wonders/openssh-9.8p1/contrib/redhat/sshd.init /etc/init.d/sshd
#给sshd的配置文件执行权限
chmod u+x /etc/init.d/sshd
#添加sshd服务
chkconfig --add sshd
#验证开机启动
chkconfig --list|grep sshd

#5. 设置 ssh -V验证码版本
#备份配置文件
mv /etc/ssh/sshd_config /etc/ssh/sshd_config.bak
#替换配置文件
cp /usr/wonders/openssh-9.8p1/sshd_config /etc/ssh/sshd_config
#配置sshd_config文件
#将subsystem sftp路径变更为实际路径/usr/local/openssh/libexec/sftp-server
vim /etc/ssh/sshd_config
#Subsystem sftp /usr/libexec/sftp-server
注释掉,换为如下一句:
Subsystem sftp /usr/local/openssh/libexec/sftp-server
#备份配置文件
mv /usr/sbin/sshd /usr/sbin/sshd.bak
#拷贝配置文件
cp /usr/local/openssh/sbin/sshd /usr/sbin/sshd
#拷贝sshd命令至/usr/bin/
cp /usr/local/openssh/bin/ssh /usr/bin/

#6. 检查版ssh本
ssh -V

#7. 密码认证和允许root用户远程直接登录
#拷贝ssh-keygen
mv /usr/bin/ssh-keygen /usr/bin/ssh-keygen.bak
cp /usr/local/openssh/bin/ssh-keygen /usr/bin/ssh-keygen
ln -s /usr/local/openssh/sbin/sshd /sbin/sshd
ln -s /usr/local/openssh/bin/ssh-keygen /usr/bin/sshkeygen
#修改配置文件/etc/ssh/sshd_config
vi /etc/ssh/sshd_config
#PasswordAuthentication yes 行取消注释
PasswordAuthentication yes
#并下面添加
PermitRootLogin yes
#PS:如果不允许root用户远程直接登录,这里配置为PermitRootLogin no

#8. 重启sshd服务
service sshd restart

#9. 验证sshd是否有效
systemctl is-active sshd
#查看22端口监听
netstat -an |grep LISTEN|grep :22

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值