Centos 6.5、7升级安装openssh8.2p1

因centos7自带的ssh版本较低,存在高危漏洞,故升级到最新版本(目前是8.2p1)

注意:
升级ssh存在一定的危险性,一旦不成功可能无法通过远程连接到系统,因此在升级之前最好先安装vnc或者telnet等远程服务

1. 准备工作

查看下当前SSH和SSL版本:

[root@centos73_test ~]# ssh -V
OpenSSH_7.4p1, OpenSSL 1.0.2k-fips  26 Jan 2017
[root@centos73_test ~]# openssl version
OpenSSL 1.0.2k-fips  26 Jan 2017
[root@centos73_test ~]# rpm -qa | grep openssh
openssh-clients-7.4p1-11.el7.x86_64
openssh-server-7.4p1-11.el7.x86_64
openssh-7.4p1-11.el7.x86_64

若提示

openssl: error while loading shared libraries: libssl.so.1.1: cannot open shared object file: No such file or directory

请谨慎操作:

[root@centos73_test ~]# ln -s /usr/local/lib64/libssl.so.1.1 /usr/lib64/libssl.so.1.1
[root@centos73_test ~]# ln -s /usr/local/lib64/libcrypto.so.1.1 /usr/lib64/libcrypto.so.1.1

再次确定ssl版本

[root@centos73_test ~]# openssl version
OpenSSL 1.0.2k-fips  26 Jan 2017

下载最新版openssh:

[root@centos73_test ~]# wget https://openbsd.hk/pub/OpenBSD/OpenSSH/portable/openssh-8.2p1.tar.gz
或者是
[root@centos73_test ~]# wget https://mirrors.sonic.net/pub/OpenBSD/OpenSSH/portable/openssh-8.2p1.tar.gz
[root@centos73_test ~]# wget https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/

官方下载网站:

http://www.openssh.com/portable.html

备份ssh:

[root@centos73_test ~]# cp -r /etc/ssh/ /etc/ssh_bak
2、编译安装openssh

解压安装包:

[root@centos73_test ~]# tar -zxf openssh-8.2p1.tar.gz

编译:

[root@centos73_test ~]# cd openssh-8.2p1/
[root@centos73_test openssh-8.2p1]#  ./configure --prefix=/usr --sysconfdir=/etc/ssh
checking for cc... no
checking for gcc... no
configure: error: in `/root/openssh-8.2p1`:
configure: error: no acceptable C compiler found in $PATH

需要gcc编译器的,我在这里是用yum安装的:
[root@centos73_test openssh-8.2p1]# yum -y install gcc

再次执行编译命令
[root@centos73_test openssh-8.2p1]# ./configure --prefix=/usr --sysconfdir=/etc/ssh

报错一:

如果报错:
configure: error: *** zlib.h missing - please install first or check config.log ***
需要安装zlib-devel
[root@centos73_test openssh-8.2p1]# yum install -y zlib-devel

报错二:

如果报错:
configure: error: *** OpenSSL headers missing - please install first or check config.log ***
configure: error: *** working libcrypto not found, check config.log
需要安装openssl-devel包
[root@centos73_test openssh-8.2p1]# yum -y install openssl-devel

报错三:

如果报错:
checking whether OpenSSL's headers match the library... no
configure: error: Your OpenSSL headers do not match your
        library. Check config.log for details.
        If you are sure your installation is consistent, you can disable the check
        by running "./configure --without-openssl-header-check".
        Also see contrib/findssl.sh for help identifying header/library mismatches.

添加`--without-openssl-header-check`参数继续编译
 ./configure --prefix=/usr --sysconfdir=/etc/ssh  --without-openssl-header-check

解决完报错后重新执行 ./configure --prefix=/usr --sysconfdir=/etc/ssh

完成后执行make:

[root@centos73_test openssh-8.2p1]# make
make完成后先不要make install,先卸载旧版的openssh
[root@centos73_test openssh-8.2p1]# rpm -e --nodeps `rpm -qa | grep openssh`

完成后执行make install:

[root@centos73_test openssh-8.2p1]# make install

提示以下等多个WARNING

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0640 for '/etc/ssh/ssh_host_rsa_key' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0640 for '/etc/ssh/ssh_host_ecdsa_key' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0640 for '/etc/ssh/ssh_host_ed25519_key' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
sshd: no hostkeys available -- exiting.
make: [check-config] 错误 1 (忽略)

将对应目录修改600权限即可

[root@centos73_test openssh-8.2p1]# chmod 600 /etc/ssh/ssh_host_rsa_key /etc/ssh/ssh_host_ecdsa_key /etc/ssh/ssh_host_ed25519_key

查看下安装结果:

[root@centos73_test openssh-8.2p1]# ssh -V
OpenSSH_8.2p1, OpenSSL 1.0.2k-fips  26 Jan 2017

至此编译安装完成。

3、配置sshd服务

源码编译安装的openssh提供sys-V脚本启动,自动支持systemd启动方式,无需再修改

复制启动文件到/etc/init.d/下并命名为sshd:

[root@centos73_test openssh-8.2p1]# cp contrib/redhat/sshd.init /etc/init.d/sshd

加入开机启动:

[root@centos73_test openssh-8.2p1]# chkconfig --add sshd
4、配置允许root使用ssh

openssh8.2默认root用户是不能用ssh远程登录的,需要修改配置文件:

[root@centos73_test  openssh-8.2p1]# vim /etc/ssh/sshd_config
找到#PermitRootLogin prohibit-password项,去掉注释并把prohibit-password改为yes
PermitRootLogin yes

有可能还需要修改PasswordAuthentication
PasswordAuthentication yes

重启ssh服务:

[root@centos73_test openssh-8.2p1]# service sshd restart

如果连不上注意检查以上内容及关闭selinux

[root@centos73_test  openssh-8.2p1]# setenforce 0
[root@centos73_test  openssh-8.2p1]# sed -i s#SELINUX=enforcing#SELINUX=disabled# /etc/selinux/config

至此升级/安装完成。

4、升级后的问题

openssh升级后很可能因为新的算法等原因,出现以下类型情况:

Key exchange failed.
No compatible key exchange method. The server supports these methods: curve25519-sha256,curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group14-sha256

解决方法:

  1. 升级CRT、Xshell 等客户端ssh工具至最新版测试,如不行使用2方法
  2. 修改/etc/ssh/sshd_config配置
[root@centos73_test openssh-8.2p1]# vi /etc/ssh/sshd_config		//最后行添加以下内容
KexAlgorithms curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1,diffie-hellman-group1-sha1
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
CentOS 7上升级安装OpenSSH 9.1可以按照以下步骤进行: 1. 首先,确保系统已经安装了EPEL存储库。如果未安装,请运行以下命令安装: ``` sudo yum install epel-release ``` 2. 然后,更新系统软件包到最新版本: ``` sudo yum update ``` 3. 安装OpenSSH 9.1的依赖软件包: ``` sudo yum install gcc make wget perl-devel pam-devel zlib-devel krb5-devel openssl-devel ``` 4. 下载OpenSSH 9.1的源代码包,可以在OpenSSH官方网站上获取最新的源代码包: ``` wget http://www.openssh.com/portable/openssh-9.1p1.tar.gz ``` 5. 解压源代码包: ``` tar -zxvf openssh-9.1p1.tar.gz cd openssh-9.1p1 ``` 6. 配置编译选项: ``` ./configure --prefix=/usr --sysconfdir=/etc/ssh --with-md5-passwords --with-privsep-path=/var/empty/sshd ``` 7. 编译并安装: ``` make sudo make install ``` 8. 备份并替换系统原有的OpenSSH二进制文件: ``` sudo cp /usr/sbin/sshd /usr/sbin/sshd_backup sudo cp /usr/bin/ssh /usr/bin/ssh_backup sudo cp /usr/bin/ssh-keygen /usr/bin/ssh-keygen_backup sudo cp /usr/libexec/openssh/sftp-server /usr/libexec/openssh/sftp-server_backup sudo cp /usr/libexec/openssh/sftp-server /usr/libexec/openssh/sftp-server_backup sudo cp /usr/libexec/openssh/sftp-server /usr/libexec/openssh/sftp-server_backup sudo cp /usr/libexec/openssh/ssh-keysign /usr/libexec/openssh/ssh-keysign_backup sudo cp /usr/libexec/openssh/ssh-keyscan /usr/libexec/openssh/ssh-keyscan_backup sudo cp /usr/libexec/openssh/ssh-keyscan /usr/libexec/openssh/ssh-keyscan_backup ``` 9. 启动OpenSSH服务: ``` sudo systemctl start sshd ``` 到此,您已成功将OpenSSH升级到9.1版本。您可以使用以下命令验证OpenSSH版本: ``` ssh -V ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值