Centos8利用rpm升级OpenSSH到openssh-8.3p1版本

Centos8默认自带的openssh版本为7.8,已经不满足现阶段的安全需求,所有博客制作了一个openssh8.3p1适用于Centos8使用的版本。

下载:

wget https://cikeblog.com/s/openssh8.3-8.tar.gz
tar -zxvf openssh8.3-8.tar.gz

安装方法一:

rpm -Uvh *.rpm

安装方法二(此方法会自动处理依懒关系):

yum install ./*.rpm

安装后会如下提示:

[root@test ~]# rpm -Uvh *.rpm
Preparing...                          ################################# [100%]
Updating / installing...
   1:openssh-8.1p1-1.el7              ################################# [ 14%]
   2:openssh-clients-8.1p1-1.el7      ################################# [ 29%]
   3:openssh-server-8.1p1-1.el7       ################################# [ 43%]
   4:openssh-debuginfo-8.1p1-1.el7    ################################# [ 57%]
[root@test ~]# ssh -V
OpenSSH_8.1p1, OpenSSL 1.0.1e-fips 11 Feb 2013
[root@768 ~]#

注意:升级后重启SSH可能出现以下错误:

It is required that your private key files are NOT accessible by others.
This private key will be ignored.
Unable to load host key "/etc/ssh/ssh_host_ed25519_key": bad permissions
Unable to load host key: /etc/ssh/ssh_host_ed25519_key
sshd: no hostkeys available -- exiting.
[FAILED]
sshd.service: control process exited, code=exited status=1
Failed to start SYSV: OpenSSH server daemon.
Unit sshd.service entered failed state.
sshd.service failed.

解决办法:

chmod 0600 /etc/ssh/ssh_host_ed25519_key
service sshd restart

至此,升级完成,因为OPENSSH升级后,/etc/ssh/sshd_config会还原至默认状态,我们需要进行相应配置:

cd /etc/ssh/
chmod 400 ssh_host_ecdsa_key ssh_host_ed25519_key ssh_host_rsa_key
echo "PermitRootLogin yes" >> /etc/ssh/sshd_config
echo "PasswordAuthentication yes"  >> /etc/ssh/sshd_config
systemctl restart sshd

并且,/etc/pam.d/sshd也文件会被覆盖,我们进行还原:
先清空:

>/etc/pam.d/sshd;

再还原:

echo '#%PAM-1.0
auth       required     pam_sepermit.so
auth       include      password-auth
account    required     pam_nologin.so
account    include      password-auth
password   include      password-auth
# pam_selinux.so close should be the first session rule
session    required     pam_selinux.so close
session    required     pam_loginuid.so
# pam_selinux.so open should only be followed by sessions to be executed in the user context
session    required     pam_selinux.so open env_params
session    optional     pam_keyinit.so force revoke
session    include      password-auth'>/etc/pam.d/sshd

至此,升级完成,先别关闭终端,直接新开一个终端,连接到服务器测试。

注意:如果新开终端连接的时,root密码报错,并且已经根据上面后续操作,那可能就是SElinux的问题,我们进行临时禁用:

setenforce 0

即可正常登录,然后修改/etc/selinux/config 文件:

sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config

进行永久禁用SElinux即可。

» 本文链接:Centos8利用rpm升级OpenSSH到openssh-8.3p1版本
» 转载请注明来源:刺客博客
» 如果文章失效或者安装失败,请留言进行反馈。
评论 ( 1)
  1. avatar
    沙发
    fatboy 2020-11-08 11:05

    根据您的文档升级RHEL8.2的ssh到openssh8.3,升级完以后发现登录,selinux已经关闭,看报错,说找不到selinux.sh里面的open模块
    session required pam_selinux.so open env_params
    session required pam_selinux.so close 注释掉这两个就好了