试了几种方法,最后都多少有点问题,最后尝试了这篇博文,全程无报错。CentOS7 OpenSSL升级到OpenSSH9.5p1_checking openssl library version... configure: err-CSDN博客
全程使用telnet操作
1.安装依赖包
[root@localhost ~]# yum -y install pam* zlib*
2.查看openssh位置,备份
[root@localhost ~]# whereis ssh sshd
ssh: /usr/bin/ssh /etc/ssh /usr/share/man/man1/ssh.1.gz
sshd: /usr/sbin/sshd /usr/share/man/man8/sshd.8.gz
[root@localhost ~]# mv /etc/ssh /etc/ssh.bak
[root@localhost ~]# mv /usr/bin/ssh /usr/bin/ssh.bak
[root@localhost ~]# mv /usr/sbin/sshd /usr/sbin/sshd.bak
[root@localhost ~]# mv /etc/pam.d/sshd /etc/pam.d/sshd.old
3.卸载原来的版本
[root@localhost ~]# yum remove openssh -y
4.安装新版本
[root@localhost ~]# tar zxvf openssh-9.8p1.tar.gz
[root@localhost openssh-9.8p1]#./configure --prefix=/usr --sysconfdir=/etc/ssh --with-pam --with-ssl-dir=/usr/local/openssl/lib64/
#with-ssl-dir后面跟的是之前openssl安装时的位置,/usr/local/openssl
[root@localhost openssh-9.8p1]# make && make install
5.恢复pam文件
[root@localhost ~]# cd /etc/pam.d/
[root@localhost pam.d]# mv sshd.old sshd
6.启动服务
[root@localhost openssh-9.8p1]# cp contrib/redhat/sshd.init /etc/init.d/sshd
[root@localhost openssh-9.8p1]# chkconfig --add sshd
[root@localhost openssh-9.8p1]# systemctl enable sshd
[root@localhost openssh-9.8p1]# systemctl start sshd
此时,还不能正常登录,需要继续配置sshd_config
[root@localhost pam.d]# vim /etc/ssh/sshd_config
#使用:set number
找到32行,复制一行改为PermitRootLogin yes
58行,改为PasswordAuthentication yes
82行,改为UsePAM yes 这一行必须有,不然登录不上去
[root@localhost pam.d]# systemctl restart sshd
#重新启动服务
原先ssh登录使用的时xshell5,再次ssh远程登录时,有如下提示:
按照其他博文里说的,尝试去掉sshd_config文件里#HostKey /etc/ssh/ssh_host_ed25519_key
前面的注释,重启服务后仍然无法登录。
使用xshell7登录,没有此类问题,可以直接登录。
7.恢复图形化界面
卸载openssh后,虚拟机图形化界面也会收到影响,重新安装好openssh后,得记得把图形化界面也安装回来。
[root@localhost ~]# yum groups list
已加载插件:fastestmirror, langpacks
没有安装组信息文件
Maybe run: yum groups mark convert (see man yum)
Loading mirror speeds from cached hostfile
可用的环境分组:
最小安装
基础设施服务器
计算节点
文件及打印服务器
基本网页服务器
虚拟化主机
带 GUI 的服务器
GNOME 桌面
KDE Plasma Workspaces
开发及生成工作站
可用组:
传统 UNIX 兼容性
兼容性程序库
图形管理工具
安全性工具
开发工具
控制台互联网工具
智能卡支持
科学记数法支持
系统管理
系统管理工具
完成
#安装GNOME 桌面
[root@localhost ~]# yum groups install GNOME 桌面 -y
#安装结束后,启动界面
[root@localhost ~]# startx
此时再查看虚拟机,已从命令行恢复成图形化界面。