本文共 2141 字,大约阅读时间需要 7 分钟。
wget -O /etc/yum.repos.d/CentOS-Base.repowget -O /etc/yum.repos.d/epel.repo
SSH服务作为远程登录的重要通道,如果存在安全漏洞,可能导致 unauthorized access。为此,我们需要升级SSH版本并采取其他安全措施。
ssh -V
如果当前版本较低,建议立即升级。
如果已配置了第三方YUM源,可以使用YUM直接升级:
yum update openssh -y
注意:这要求已添加了支持最新版本的第三方YUM源。
对于需要最新版本或特定配置的场景,建议采用源码编译安装。
yum -y install gcc gcc-c++ zlib zlib-devel openssl openssl-devel pam-devel libselinux-devel
wget -c https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-8.3p1.tar.gz
mkdir /opt/sshbakmv /etc/ssh/* /opt/sshbak/
mkdir /usr/local/sshd
tar xf openssh-8.3p1.tar.gz -C /usr/local/src/cd /usr/local/src/openssh-8.3p1./configure --with-md5-passwords --with-pam --with-selinux --with-privsep-path=/usr/local/sshd/ --sysconfdir=/etc/sshmake -j4make install
修改 /etc/ssh/sshd_config:
vim /etc/ssh/sshd_config
PermitRootLogin 行,将其设置为: PermitRootLogin yes
PubkeyAuthentication 行,去掉注释: PubkeyAuthentication yes
UseDNS no
yum install xinetd telnet-server -y
mv /etc/xinetd.d/telnet /opt/sshbak/
systemctl enable xinetd && systemctl start xinetdsystemctl enable telnet.socket && systemctl start telnet.socket
cp contrib/redhat/sshd.init /etc/init.d/sshdsed -i 's#SSHD=/usr/sbin/sshd#SSHD=/usr/local/sbin/sshd#g' /etc/init.d/sshdsed -i 's#/usr/bin/ssh-keygen#/usr/local/bin/ssh-keygen#g' /etc/init.d/sshd
chkconfig --add sshdchkconfig sshd on
mv /usr/lib/systemd/system/sshd.service /opt/sshbak/
/etc/init.d/sshd restartnetstat -ntup | grep 22
重新编译安装时,修改 version.h:
vim version.h
将开头部分修改为:
#define SSH_VERSION "ctyun_cloud"
然后重新编译安装:
make -j4make installsystemctl restart sshd
systemctl disable xinetd.servicesystemctl stop xinetdsystemctl disable telnet.socketsystemctl stop telnet.socket
通过以上步骤,您可以在CentOS 7.5环境下安全地升级和配置SSH服务,保障服务器的安全性。
转载地址:http://qznuz.baihongyu.com/