因为项目构建时间比较长,近期安全检查发现openssh有漏洞。因此要升级openssh到7.9p1版本。因为ssh用于远程链接,因此要谨慎操做。node
一、 依赖安装安全
OpenSSL版本:目前OpenSSH7.9不支持OpenSSH1.1.x以上。不然编译的时候会报错。bash
Zlib1.1.4或1.2.1.2或更高版本;服务器
gcc:由于编译须要gcc;ssh
openssl-devel:编译时须要spa
二、下载openssh 7.9rest
wget https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-7.9p1.tar.gz
三、卸载旧的opehsshcode
rpm -qa |grep openssh rpm -e --nodeps openssh-clients-7.4p1-11.el7.x86_64 rpm -e --nodeps openssh-7.4p1-11.el7.x86_64 rpm -e --nodeps openssh-server-7.4p1-11.el7.x86_64 rpm -qa |grep openssh
若是以前就是源码安装的,找到以前的安装包,在里面执行cdn
make uninstall
四、解压并安装server
4.1)解压
tar xf openssh-7.9p1.tar.gz cd openssh-7.9p1 4.2)编译 ./configure --prefix=/usr --sysconfdir=/etc/ssh --with-md5-passwords --with-privsep-path=/var/lib/sshd
make
注意!!!
注意!!!
注意!!!
① configure: error: no acceptable C compiler found in $PATH
问题解决
yum install gcc
② configure: error: * zlib.h missing - please install first or check config.log *
问题解决
安装相关依赖包
yum install openssl openssl-devel -y
4.3)修改文件权限不然会安装报错
chmod 600 /etc/ssh/ssh_host_rsa_key
chmod 600 /etc/ssh/ssh_host_ecdsa_key
chmod 600 /etc/ssh/ssh_host_ed25519_key
4.4)安装
make install
五、配置
install -v -m755 contrib/ssh-copy-id /usr/bin
install -v -m644 contrib/ssh-copy-id.1 /usr/share/man/man1
install -v -m755 -d /usr/share/doc/openssh-7.9p1
install -v -m644 INSTALL LICENCE OVERVIEW README*
install -v -m644 INSTALL LICENCE OVERVIEW README* /usr/share/doc/openssh-7.9p1
命令解释:
--sysconfdir=/etc/ssh:这能够防止安装配置文件 /usr/etc。
--with-md5-passwords:这使得可使用MD5密码。
--with-pam:此参数在构建中启用 Linux-PAM支持。
--with-xauth=/usr/bin/xauth:为X身份验证设置xauth二进制文件的默认位置。若是将xauth安装到其余路径,请更改位置。这也能够sshd_config使用XAuthLocation关键字进行控制。若是已安装Xorg,则能够省略此开关。
--with-kerberos5=/usr:此选项用于在构建中包含Kerberos 5支持。
--with-libedit:此选项为sftp启用行编辑和历史记录功能。
六、根据自身需求改写配置文件。由于配置文件为初始配置文件。因此和以前的不同。可使用备份配置文件覆盖。
注意:
默认是22端口,可是不能root直接登陆。若是想直接使用root登陆执行如下命令
echo "PermitRootLogin yes" >> /etc/ssh/sshd_config
七、配置开机启动并重启
cp -p contrib/redhat/sshd.init /etc/init.d/sshd chmod +x /etc/init.d/sshd chkconfig --add sshd chkconfig sshd on chkconfig --list sshd systemctl restart sshd
八、重启服务器
reboot
脚本:
该脚本在确认好本机环境的状况后执行 !!!
cat openssh_7.9.1_update.sh
#!/bin/bash rpm -qa |grep zlib rpm -qa |grep openssl rpm -qa |grep openssh gcc --version read -p "是否继续[y/n]" Check if [ $Check == 'y' ] then for rpmpkgs in `rpm -qa |grep openssh`; do rpm -e --nodeps ${rpmpkgs} ;done sleep 1 rpm -qa |grep openssh mkdir /tmp/opensshupdate -p cd /tmp/opensshupdate && wget https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-7.9p1.tar.gz ./configure --prefix=/usr --sysconfdir=/etc/ssh --with-md5-passwords --with-privsep-path=/var/lib/sshd make sleep 1 chmod 600 /etc/ssh/ssh_host_rsa_key chmod 600 /etc/ssh/ssh_host_ecdsa_key chmod 600 /etc/ssh/ssh_host_ed25519_key make install sleep 1 install -v -m755 contrib/ssh-copy-id /usr/bin install -v -m644 contrib/ssh-copy-id.1 /usr/share/man/man1 install -v -m755 -d /usr/share/doc/openssh-7.9p1 install -v -m644 INSTALL LICENCE OVERVIEW README* install -v -m644 INSTALL LICENCE OVERVIEW README* /usr/share/doc/openssh-7.9p1 sleep 1 echo "PermitRootLogin yes" >> /etc/ssh/sshd_config sleep 1 cp -p contrib/redhat/sshd.init /etc/init.d/sshd chmod +x /etc/init.d/sshd chkconfig --add sshd chkconfig sshd on chkconfig --list sshd systemctl restart sshd else break fi