CentOS7升级openssh,离线,在线两种方式,亲测可用

准备工作

由于openssh安装可能会造成ssh无法使用,所以要先安装telnet,保证可以使用telnet协议登录服务器,以免对生产环境造成其他影响

所有需要的包都在百度网盘中
链接:https://pan.baidu.com/s/1goo1Px40jF92tjHAjNNd4A
提取码:upev

版本下载地址:https://openbsd.hk/pub/OpenBSD/OpenSSH/portable/

#备份文件
cp -rf /etc/ssh/ /etc/ssh.bak
cp -rf /usr/local/openssh/ /usr/local/openssh.bak cp -rf /etc/init.d/sshd /etc/init.d/sshd.bak
cp -rf /usr/sbin/sshd /usr/sbin/sshd.bak
cp -rf /usr/bin/ssh /usr/bin/ssh.bak
cp -rf /usr/bin/ssh-keygen /usr/bin/ssh-keygen.bak

  • 安装telent

#查看selinux的状态,必须为关闭状态
[root@localhost ~]# getenforce
Disabled
#查看防火墙的状态,必须为关闭状态
systemctl status firewalld
systemctl stop firewalld
(1).安装telnet
yum install -y xinetd
yum install -y telnet
yum install -y telnet-server
(2)允许root用telnet登陆
#增加pts配置;如果登录用户较多,需要更多的pts/*
vim /etc/securetty
在末尾添加:
pts/0
pts/1
pts/2
pts/3
(3)如果没有则不修改
[root@localhost ~]# vim /etc/xinetd.d/telnet
###################
disable = no #开启telnet服务功能,否则telnet启动后,23端口起不来
(4)重启服务
systemctl enable xinetd
systemctl enable telnet.socket
systemctl start telnet.socket
systemctl start xinetd
(5)检测端口
netstat -lntp|grep 23
测试:telnet 127.0.0.1
useradd test1
passwd test1
test1
提权
vi /etc/sudoers
(6)#切换到telnet方式登录,以后的操作都在telnet终端下操作,防止ssh连接意外中断造成升级失败

在线安装openssh
(1)#卸载旧版本的ssh
rpm -aq openssh
rpm -e --nodeps openssh-7.4p1-21.el7.x86_64
(2)#下载高版本的ssh,然后上传解压
#免编译(#上传编译好的openssh-8.6p1到/opt下、#上传openssh到/usr/local下)
#编译
yum install -y gcc gcc-c++ glibc make autoconf openssl openssl-devel pcre-devel pam-devel
./configure --prefix=/usr/local/openssh --with-zlib=/usr/local/zlib --with-ssl-dir=/usr/local/ssl
make && make install
(3)#启动前要将新生成的sshd_config修改以下几个地方
vim /usr/local/openssh/etc/sshd_config
PermitRootLogin yes
PubkeyAuthentication yes
PasswordAuthentication yes
(4)#复制文件到相应系统文件夹
cp /opt/openssh-8.6p1/contrib/redhat/sshd.init /etc/init.d/sshd
#设置生效
chkconfig --add sshd
cp /usr/local/openssh/etc/sshd_config /etc/ssh/sshd_config
cp /usr/local/openssh/sbin/sshd /usr/sbin/sshd
cp /usr/local/openssh/bin/ssh /usr/bin/ssh
cp /usr/local/openssh/bin/ssh-keygen /usr/bin/ssh-keygen
cp /usr/local/openssh/etc/ssh_host_ecdsa_key.pub /etc/ssh/ssh_host_ecdsa_key.pub
(5)#重启服务
systemctl restart sshd
service sshd restart
(6)#验证
ssh -V #验证是否升级成功

离线安装openssh
(1)备份
cp -rf /etc/ssh/ /etc/ssh.bak
(2)上传
上传openssh到opt下,然后解压
(3)#启动前要将新生成的sshd_config修改以下几个地方
vim /usr/local/openssh/etc/sshd_config
PermitRootLogin yes
PubkeyAuthentication yes
PasswordAuthentication yes
(4)复制文件
复制文件到相应系统文件夹
cp /opt/openssh-8.6p1/contrib/redhat/sshd.init /etc/init.d/sshd
chkconfig --add sshd
cp /opt/openssh/etc/sshd_config /etc/ssh/sshd_config
cp /opt/openssh/sbin/sshd /usr/sbin/sshd
cp /usr/local/openssh/bin/ssh /usr/bin/ssh
cp /usr/local/openssh/bin/ssh-keygen /usr/bin/ssh-keygen
cp /usr/local/openssh/etc/ssh_host_ecdsa_key.pub /etc/ssh/ssh_host_ecdsa_key.pub
(5)#重启服务
systemctl restart sshd
service sshd restart
(6)#验证
ssh -V #验证是否升级成功

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值