Linux 系统安装完后就可以用了吗?其实还有一些后续工作需要做( 二 )


DisableForwarding yes在 Ubuntu 中,添加 DisableForwarding yes 到 10-my-sshd-settings.conf 文件中,如下:
sudo echo "DisableForwarding yes" >> /etc/ssh/sshd_config.d/10-my-sshd-settings.conf8,禁止 root 用户登录 ssh几乎每个 Linux 系统中都有 root 用户,允许其登录 ssh 是比较危险的 。
在 CentOS 或 Red Hat 中,在文件 /etc/ssh/sshd_config 中找到 PermitRootLogin yes,将其改为:
PermitRootLogin noUbuntu 中,在10-my-sshd-settings.conf 文件中添加 PermitRootLogin no:
sudo echo "PermitRootLogin no" >> /etc/ssh/sshd_config.d/10-my-sshd-settings.conf9,禁用基于密码的 ssh 身份验证在禁用 ssh 密码验证之前,首先需要按照第 3 点中所属配置和测试了基于密钥的身份验证 。
我们在先前的文章中介绍过如何禁用基于密码的 ssh 身份验证,可参考:??如何禁止使用密码通过 ssh 连接远程服务器??
CentOS 或 Red Hat 中,在文件 /etc/ssh/sshd_config 中找到 PasswordAuthentication yes,将其改为:
PasswordAuthentication no在 Ubuntu 中,在文件 10-my-sshd-settings.conf 中添加内容 PasswordAuthentication no:
sudo echo "PasswordAuthentication no" >> /etc/ssh/sshd_config.d/10-my-sshd-settings.conf10,忽略 rhostsrhosts 与 rsh 相关联,rsh 是一种被 secure shell 取代的遗留协议 。如果用户试图创建恶意 rhosts 文件,此设置将忽略它 。
CentOS 或 Red Hat 系统中,在文件 /etc/ssh/sshd_config 中找到 #IgnoreRhosts yes 将前面的#删掉(即注释打开):
IgnoreRhosts yesUbuntu 中,在文件 10-my-sshd-settings.conf 中添加 IgnoreRhosts yes:
sudo echo "IgnoreRhosts yes" >> /etc/ssh/sshd_config.d/10-my-sshd-settings.conf11,安装配置 fail2ban 来加强 ssh 安全性Fail2ban会监视已配置服务(如SSH)的日志文件,并阻止恶意用户的IP地址在设定的时间内多次尝试后连接到您的服务器 。
例如,如果攻击者在三小时内进行了5次以上的失败尝试,他的IP地址将被封锁12小时 。
Fail2ban 也可以配置为保护其他服务,例如由 Nginx web 服务器或 Apache web 服务器支持的网站 。
12,配置自动安全更新(适用于Red Hat和CentOS)如前所述,如果漏洞比较多,带有漏洞的过时服务可能会让攻击者进入你的服务器,甚至无需登录!快速应用安全更新以降低此风险至关重要 。
Ubuntu 会默认启用自动安全更新,所以无需执行更新操作 。
要在 CentOS 和 Red Hat 上配置自动更新,需要安装一个名为 dnf-automatic  的应用程序,并使用以下命令为其启用计时器:?
sudo dnf upgradesudo dnf install dnf-automatic -ysudo systemctl enable --now dnf-automatic.timer然后通过如下命令来检查一下:
sudo systemctl status dnf-automatic.timer



推荐阅读