因为目前服务器上ssh版本较低,存在安全漏洞,须要升级到最新版本。node
系统版本:RedHat 7.0vim
旧openSSH版本:6.4p1安全
新openSSH版本:7.4p1bash
升级方式:源码安装服务器
安装操做步骤以下:ssh
一、更新sslui
#yum update openssl spa
二、备份ssh目录.net
#cp -rf /etc/ssh /etc/ssh.bak 3d
注:安装telnet,以备ssh更新失败没法远程链接,若是能够现场操做可忽略
三、安装升级所需组件
#yum install -y gcc openssl-devel pam-devel rpm-build
四、解压升级包,并安装
tar -zxvf openssh-7.4p1.tar.gz cd openssh-7.4p1 ./configure --prefix=/usr --sysconfdir=/etc/ssh --with-pam --with-zlib --with-md5-passwords make && make install
或者yum源安装
#yum -y install openssh openssh-clients openssh-server
须要安装客户端和服务端、启动服务端和设置下开机启动。
五、修改配置文件
vim /etc/ssh/sshd_config
1)、修改PermitRootLogin
#PermitRootLogin yes
修改成
PermitRootLogin yes
2)、注释掉下面的新版本不支持的配置
#GSSAPIAuthentication yes
#GSSAPICleanupCredentials yes
编辑脚本ssh_chmod.sh并执行(这是执行查看状态发现权限不对进行相应的修改,可根据状况自行设置)
#!/bin/bash cd /etc/ssh chmod 600 ssh_host_rsa_key chmod 640 ssh_host_ed25519_key chown -R root:ssh_keys ssh_host_ed25519_key chmod 600 ssh_host_ecdsa_key
六、重启SSH
#systemctl restart sshd
七、查看SSH状态
#systemctl status sshd
如需提早卸载旧版,可按照下述步骤操做
一、查看旧版openSSH
#rpm -qa | grep openssh
二、卸载旧版openSSH
#rpm -e `rpm -qa | grep openssh` --nodeps
注:
一、在configure openssh时,若是有参数 –with-pam,会提示:“PAM is enabled. You may need to install a PAM control file for sshd, otherwise password authentication may fail. Example PAM control files can be found in the contrib/ subdirectory”提示文字,
就是若是启用PAM,须要有一个控制文件,按照提示的路径找到redhat/sshd.pam,并复制到/etc/pam.d/sshd,在/etc/ssh/sshd_config中打开UsePAM yes。发现链接服务器被拒绝,关掉就能够登陆
https://blog.csdn.net/mayifan0/article/details/73293419