`允許特定端口的訪問,例如`sudo ufw allow ssh`允許ssh訪問。
– centos/RHEL:`sudo yum install firewalld`,然后使用`sudo systemctl enable firewalld`啟用防火墻。使用`sudo firewall-cmd –zone=public –add-port=/tcp –permanent`允許特定端口的訪問。
2. 禁用不必要的服務:
– 使用`sudo systemctl list-unit-files –type=service`列出所有服務。使用`sudo systemctl disable?`禁用不必要的服務,例如`sudo systemctl disable telnet`禁用Telnet服務。
3. 配置ssh:
– 編輯ssh配置文件:`sudo nano /etc/ssh/sshd_config`。
– 禁用root登錄:將`PermitRootLogin`設置為`no`。
– 禁用密碼登錄:將`PasswordAuthentication`設置為`no`。
– 重啟ssh服務:`sudo systemctl restart sshd`。
4. 更新系統和軟件包:
– Ubuntu/Debian:`sudo apt-get update && sudo apt-get upgrade`。
– centos/RHEL:`sudo yum update`。
5. 配置登錄限制:
– 編輯登錄限制文件:`sudo nano /etc/login.defs`。
– 修改`PASS_MAX_DAYS`和`PASS_MIN_DAYS`以限制密碼更改的間隔。
– 修改`PASS_WARN_AGE`以設置密碼過期警告的天數。
– 使用`sudo nano /etc/seLinux/config`編輯SELinux配置文件。
– 重啟系統以應用更改。
7. 安裝并配置fail2ban:
– Ubuntu/Debian:`sudo apt-get install fail2ban`。
– centos/RHEL:`sudo yum install epel-release`,然后`sudo yum install fail2ban`。
– 編輯主配置文件:`sudo nano /etc/fail2ban/jail.local`。