openssh在7.8以前的版本存在安全漏洞,升级到目前的最新版7.9可以解决该问题。在yum源中目前还没有最新版的openssh,故选择编译源码安装。
操作步骤:
1.首先安装telnet服务器,防止升级失败后连不上服务器,升级后需要注意一点是要开放telnet使用的端口23。安装脚本内容如下:
echo yum install -y telnet-server
yum install -y telnet-server
echo yum install -y xinetd
yum install -y xinetd
systemctl enable xinetd.service
systemctl enable telnet.socket
systemctl start telnet.socket
systemctl start xinetd
systemctl status xinetd
systemctl restart iptables
systemctl stop iptables
2.测试telnet连接,确保telnet能登录服务器,此步骤为必须;
3.安装openssh。安装脚本内容如下:
yum remove -y openssh
install -v -m700 -d /var/lib/sshd
chown -v root:sys /var/lib/sshd
groupadd -g 50 sshd
useradd -c 'sshd PrivSep' -d /var/lib/sshd -g sshd -s /bin/false -u 50 sshd
tar -zxvf openssh-7.9p1.tar.gz
cd openssh-7.9p1
./configure --prefix=/usr --sysconfdir=/etc/ssh --with-md5-passwords --with-privsep-path=/var/lib/sshd --with-pam
make
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
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* /usr/share/doc/openssh-7.9p1
sed 's@d/login@d/sshd@g' /etc/pam.d/login > /etc/pam.d/sshd
chmod 644 /etc/pam.d/sshd
echo "UsePAM 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
rpm -qa|grep openssh
4.ssh -V 可查看当前版本;
5.另开一个终端测试ssh连接,能成功连接即ok;