因centos7自带的ssh版本较低,存在高危漏洞,故升级到最新版本(目前是7.4p1)
注: 升级ssh存在一定的危险性,一旦不成功可能无法通过远程连接到系统,因此在升级之前最好先安装vnc或者telnet等远程服务
1. 准备工作
查看下当前SSH和SSL版本:
[root@SCJG-NTP ~]# ssh -V
OpenSSH_7.4p1, OpenSSL 1.0.2k-fips 26 Jan 2017
[root@SCJG-NTP ~]# openssl version
OpenSSL 1.0.2k-fips 26 Jan 2017
[root@SCJG-NTP ~]# 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@SCJG-NTP ~]# ln -s /usr/local/lib64/libssl.so.1.1 /usr/lib64/libssl.so.1.1
[root@SCJG-NTP ~]# ln -s /usr/local/lib64/libcrypto.so.1.1 /usr/lib64/libcrypto.so.1.1
再次确定ssl版本:
[root@SCJG-NTP ~]# openssl version
OpenSSL 1.0.2k-fips 26 Jan 2017
下载最新版openssh:
[root@SCJG-NTP bak]# wget https://openbsd.hk/pub/OpenBSD/OpenSSH/portable/openssh-8.2p1.tar.gz
或者是
[root@SCJG-NTP bak]# wget https://mirrors.sonic.net/pub/OpenBSD/OpenSSH/portable/openssh-8.2p1.tar.gz
备份ssh:
[root@SCJG-NTP bak]# cp -r /etc/ssh/ /etc/ssh_bak
2、编译安装openssh
解压安装包:
[root@SCJG-NTP bak]# tar -zxf openssh-8.2p1.tar.gz
编译:
如果提示需要gcc编译器,可手动安装,我在这里是用yum安装:
[root@SCJG-NTP bak]# yum -y install gcc
[root@SCJG-NTP bak]# cd openssh-8.2p1/
[root@SCJG-NTP openssh-8.2p1]# ./configure --prefix=/usr --sysconfdir=/etc/ssh
报错一:
如果报错:
configure: error: *** zlib.h missing - please install first or check config.log ***
需要安装zlib-devel
[root@SCJG-NTP 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@SCJG-NTP 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@SCJG-NTP openssh-8.2p1]# make
make完成后先不要make install,先卸载旧版的openssh
[root@SCJG-NTP openssh-8.2p1]# rpm -e --nodeps `rpm -qa | grep openssh`
完成后执行make install:
[root@SCJG-NTP 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@SCJG-NTP openssh-8.2p1]# chmod 600 /etc/ssh/ssh_host_rsa_key /etc/ssh/ssh_host_ecdsa_key /etc/ssh/ssh_host_ed25519_key
查看下安装结果:
[root@SCJG-NTP openssh-8.2p1]# ssh -V
OpenSSH_8.2p1, OpenSSL 1.0.2k-fips 26 Jan 2017
至此编译安装完成。
3、配置sshd服务
复制启动文件到/etc/init.d/下并命名为sshd:
[root@SCJG-NTP openssh-8.2p1]# cp contrib/redhat/sshd.init /etc/init.d/sshd
加入开机启动:
[root@SCJG-NTP openssh-8.2p1]# chkconfig --add sshd
4、配置允许root使用ssh
openssh8.2默认root用户是不能用ssh远程登录的,需要修改配置文件:
[root@SCJG-NTP openssh-8.2p1]# vim /etc/ssh/sshd_config
找到#PermitRootLogin prohibit-password项,去掉注释并把prohibit-password改为yes
PermitRootLogin yes
有可能还需要修改PasswordAuthentication
PasswordAuthentication yes
重启ssh服务:
[root@SCJG-NTP openssh-8.2p1]# service sshd restart
如果连不上注意检查以上内容及关闭selinux
[root@SCJG-NTP openssh-8.2p1]# setenforce 0
[root@SCJG-NTP openssh-8.2p1]# sed -i s#SELINUX=enforcing#SELINUX=disabled# /etc/selinux/config
至此升级/安装完成。