作为一名 IT 专业人员,及时了解安全漏洞和威胁是一项挑战。 系统补丁更新、服务器和网络加固是防范安全威胁的最关键因素。 强化 Linux 服务器和网络设备对于减少 IT 漏洞和防止系统受损非常重要。 在本文中,我们将学习一些用于 Linux 服务器加固的最佳实践。 出于演示目的,我们使用 CentOS/RHEL 服务器,因此某些配置在其他 Linux 发行版上可能会有所不同。
更新 Linux 服务器
有必要使您的系统保持最新状态。 可能存在针对易受攻击组件的安全补丁更新。 运行以下命令更新系统。
$ yum update -y
启用和配置防火墙
大多数 Linux 服务器都安装了 firewalld 包。 确保 firewalld 在系统中运行。 在 Linux 系统中,可以使用 firewall-cmd 命令行实用工具来配置防火墙规则。
启动并启用防火墙服务
$ systemctl start firewalld
$ systemctl enable firewalld
要添加特定服务和端口,请使用以下语法
$ firewall-cmd --add-service=http --permanent (Allow http service)
$ firewall-cmd --add-port=8000/tcp --permanent (Allow specific port)
要反映更改,请重新加载防火墙。
$ firewall-cmd --reload
阻止 USB 驱动器
在 Linux 系统中,可以通过在下面创建配置文件来限制 USB 存储 /etc/modprobe.d/ 目录。
创建配置文件
$ touch /etc/modprobe.d/usb_block.conf
$ echo “install usb-storage /bin/false” > /etc/modprobe.d/usb_block.conf
删除不需要的用户和组
一些用户和组默认已经添加到系统中,这是不需要的。 删除此类用户和组。
$ userdel postfix
$ groupdel postfix
$ userdel games
$ groupdel games
搜索此类用户和组,并在不需要时删除。
删除不需要的包
Linux 系统中已经默认安装了一些软件包。 例如,postfix 是默认的,服务在系统启动时启动。 识别此类服务并删除它们
$ yum remove postfix -y
配置密码策略
在 Linux 机器中,密码策略在 /etc/login.defs 文件中指定。 对密码策略参数进行如下更改。
PASS_MAX_DAYS 90 PASS_MIN_DAYS 1 PASS_MIN_LENTH 8 PASS_WARN_AGE 30
例子:
配置 SSH
为了防止未经授权的 ssh 访问和攻击,请在 /etc/ssh/sshd_config 文件中进行以下更改。
# Set the custom ssh port Port 8022 # Prevent from root login PermitRootLogin no # Restrict Empty password PermitEmptyPasswords no # Restrict host-based authentications HostbasedAuthentication no IgnoreRhosts yes # Use ssh protocol 2 Protocol 2 # Disable tools that have GUI X11Forwarding no