专注于 JetBrains IDEA 全家桶,永久激活,教程
持续更新 PyCharm,IDEA,WebStorm,PhpStorm,DataGrip,RubyMine,CLion,AppCode 永久激活教程

centos7 升级openssh8.2/8.3

升级前信息: openssl version ssh -V cat /etc/redhat-release

本文 旧版本采用mv /usr/bin/ssh 改名处理

卸载旧版本openssh(有被依存关系时不能卸载)

rpm -e --nodeps `rpm -qa | grep openssh`
rpm -qa | grep openssh

==== 或: 确认OpenSSH需要删除的rpm包 rpm -qa |grep openssh

使用rpm的方式删除

rpm -e openssh openssh-clients openssh-server 

for  i   in  $(rpm  -qa  |grep  openssh);do  rpm  -e  $i  --nodeps ;done


首先打开telnet预防升级ssh不成功导致远程连接无法使用

1、安装telnet并开启

安装Telnet服务 wget www.rpmfind.net/linux/rpm2h…

1、检查是否已经安装?

rpm -qa|grep telnet*
rpm -qa|grep xinetd

2、如果没有安装过,先查找安装包

yum list |grep telnet
yum list |grep xinetd

3、执行安装命令(root用户下)

yum -y install telnet-server telnet
yum -y install xinetd

或:yum -y install telnet-server telnet xinetd 

启动Telnet服务

1、设置开机启动

systemctl enable xinetd.service
systemctl enable telnet.socket

2、开启Telnet服务

systemctl start telnet.socket
systemctl start xinetd

#重启服务命令
systemctl restart xinetd.service

3、查看Telnet和Xinetd服务状态

systemctl status xinetd.service
systemctl status telnet.socket

4、查看xinetd和Telnet是否已经启动

#查看xinetd是否启动
ps -ef | grep xinetd
#查看telnet是否启动
ps -ef | grep telnet

测试Telnet是否可连接

本机自测:

telnet localhost #或者 telnet 127.0.0.1

当看到登录提示时,表明本机的 telnet 服务已正常运行。

如果用 root 帐号登录,输入密码后,我们会发现登录失败。这是因为默认情况下,centos 系统是不允许 root 用户通过 telnet 方式远程登录系统的。如果要使 root 用户可以直接登录,需将以下内容添加到 /etc/securetty 文件末尾:

pts/0
pts/1
pts/2
pts/3

也可以通过 vi 或 vim 打开 /etc/securetty ,在文件末尾加入以上内容,或这通过以下命令直接在文件末尾追加:

echo -e ‘pts/0\npts/1\npts/2\npts/3’ >>/etc/securetty

修改后之后,需要重启telnet服务,使上述配置生效。

systemctl restart xinetd.service

开启防火墙23端口

firewall-cmd --permanent --add-port=23/tcp

firewall-cmd --zone=public --list-ports

2、设置允许root连接(默认不允许root连接)

主机端执行 tail -f /var/log/secure

客户端 telnet连接输入用户名:root

cat /etc/securetty | grep pts

pts/0 pts/1 pts/2 pts/3

这个pts/0(请根据弹出信息灵活修改)就是登录需要开放的,需要在/etc/securetty里面添加pts/0-3,即可使用root正常连接。

开始升级源码openssh,本人使用了三个版本的源码包,包括openssh-8.2p1.tar.gz、

openssl-1.1.1g.tar.gz、zlib-1.2.11.tar.gz

1、安装gcc、make命令

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

2、解压进入开始编译安装三个软件

tar zxvf openssh-8.2p1.tar.gz

tar zxvf openssl-1.1.1g.tar.gz

tar zxvf zlib-1.2.11.tar.gz

cd zlib-1.2.11./configure --prefix=/usr/local/zlib

make && make install

## cd ../openssl-1.1.1g

./config --prefix=/usr/local/ssl -d shared

## 默认没有编译出.so的文件,而openssh编译的时候需要,所以需要手动添加 -d shared的选项

make && make install

echo '/usr/local/ssl/lib' >> /etc/ld.so.conf

ldconfig -v

检查安装情况:

openssl version -a (可以看后面编译时的参数位置 –with-ssl-dir)

strings /usr/local/lib64/libssl.so | grep OpenSSL

cd ../openssh-8.3p1

./configure --prefix=/usr/local/openssh --with-zlib=/usr/local/zlib --with-ssl-dir=/usr/local/ssl

## 或(本次升级使用的)
./configure --prefix=/usr/local/openssh --with-zlib=/usr/local/zlib --with-ssl-dir=/usr/local/ssl --with-pam --with-tcp-wrappers --with-md5-passwords

make && make install

如果是采用root用户登录需要,修改openssh的配置文件

/usr/local/openssh/etc/sshd_config(取消PermitRootLogin注释并改为yes)再copy

或:直接根据需要修改/etc/ssh/sshd_config

注意升级后的路径设置:

Subsystem sftp /usr/local/openssh/libexec/sftp-server

根据需要修改配置:

CentOS和Debian通用,输入以下两条命令

sed -i 's/PermitRootLogin no/PermitRootLogin yes/g' /etc/ssh/sshd_config
sed -i 's/#PermitRootLogin yes/PermitRootLogin yes/g' /etc/ssh/sshd_config
sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/g' /etc/ssh/sshd_config

#Ubuntu系统,输入以下两条命令

sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/g' /etc/ssh/sshd_config
sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/g' /etc/ssh/sshd_config

或:

sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config  
sed -i 's/#UseDNS no/UseDNS no/' /etc/ssh/sshd_config  
sed -i 's/#PrintLastLog yes/PrintLastLog no/' /etc/ssh/sshd_config  
sed -i 's/#PrintMotd yes/PrintMotd no/' /etc/ssh/sshd_config  
sed -i 's/#X11Forwarding no/X11Forwarding yes/' /etc/ssh/sshd_config  

#=============

3、关掉旧的ssh启动新的ssh

可以ps -ef|grep sshd 直接杀死 /usr/bin/sshd的进程号

再/usr/local/openssh/sbin/sshd启动新的ssh,建议操作:

systemctl stop sshd
systemctl disable sshd

4、替换/bin下的ssh为新版的ssh


mv /usr/bin/ssh /usr/bin/ssh_bak cp /usr/local/openssh/bin/ssh /usr/bin

此时执行ssh -V即可查看现有ssh和ssl版本。

5、替换/sbin下的sshd方便开机自动启动


mv /usr/sbin/sshd /usr/sbin/sshd_bak cp /usr/local/openssh/sbin/sshd /usr/sbin/ mv /usr/bin/ssh-keygen /usr/bin/ssh-keygen.bak cp /usr/local/openssh/bin/ssh-keygen /usr/bin/ssh-keygen #可选: mv /etc/ssh/ssh_host_ecdsa_key.pub /etc/ssh/ssh_host_ecdsa_key.pub.bak cp /usr/local/openssh/etc/ssh_host_ecdsa_key.pub /etc/ssh/ssh_host_ecdsa_key.pub cp /usr/local/openssh/etc/ssh_host_rsa_key.pub /etc/ssh/ssh_host_rsa_key.pub cp /usr/local/openssh/etc/ssh_host_dsa_key.pub /etc/ssh/ssh_host_dsa_key.pub cp /usr/local/openssh/etc/ssh_host_ed25519_key.pub /etc/ssh/ssh_host_ed25519_key.pub

6、最后替换当前系统的旧版本 openssl 「先保存原来的」

mv /usr/bin/openssl /usr/bin/openssl.old
mv /usr/lib64/openssl /usr/lib64/openssl.old
mv /usr/lib64/libssl.so /usr/lib64/libssl.so.old
ln -s /usr/local/ssl/bin/openssl /usr/bin/openssl
ln -s /usr/local/ssl/include/openssl /usr/include/openssl
ln -snf /usr/local/ssl/include/openssl /usr/include/openssl
ln -s /usr/local/ssl/lib/libssl.so /usr/lib64/libssl.so

解决启动问题:

8、2升级8.3直接systemctl restart sshd

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

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

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

设置sshd服务开机启动

chkconfig sshd on

最后记得关掉或卸载telnet并取消开机自启动(明文传输不安全)

systemctl disable xinetd.service
systemctl disable telnet.socket

systemctl stop telnet.socket
systemctl stop xinetd

systemctl status telnet.socket
systemctl status xinetd.service

rpm -qa | grep telnet
#根据查出的telnet安装包,指定卸载:
rpm -e telnet-0.17-48.el6.x86_64
rpm -e telnet-server-0.17-48.el6.x86_64

升级遇到过的问题

1、如果按照流程走一般不会有问题,但是如果例如未在ssl编译处添加 -d share openssh编译容易报以下错误

此时为缺少openssl的动态库可以通过yum -y install openssl-devel 解决,安装过后编译就不需要指定openssl的具体路径了,指定至上一级即可(ssh就直接使用了yum的ssl不用源码)

2、还有编译openssl遇到缺少类似perl包的报错,一般直接yum装一下即可解决。

文章永久链接:https://tech.souyunku.com/42119

未经允许不得转载:搜云库技术团队 » centos7 升级openssh8.2/8.3

JetBrains 全家桶,激活、破解、教程

提供 JetBrains 全家桶激活码、注册码、破解补丁下载及详细激活教程,支持 IntelliJ IDEA、PyCharm、WebStorm 等工具的永久激活。无论是破解教程,还是最新激活码,均可免费获得,帮助开发者解决常见激活问题,确保轻松破解并快速使用 JetBrains 软件。获取免费的破解补丁和激活码,快速解决激活难题,全面覆盖 2024/2025 版本!

联系我们联系我们