Securing your Linux server is essential for ensuring the safety of your website and its users.
sudo apt update && sudo apt upgrade -y # For Debian-based systems
sudo dnf update -y # For RHEL-based systems
sudo apt install unattended-upgrades
sudo dpkg-reconfigure unattended-upgrades
ufw (Uncomplicated Firewall) or firewalld to restrict access:sudo ufw allow ssh
sudo ufw allow http
sudo ufw allow https
sudo ufw enable
sudo ufw allow from 192.168.1.0/24 to any port 22
/etc/ssh/sshd_config to set a custom port:Port 2222
ssh-keygen -t ed25519 -C "your_email@example.com"
ssh-copy-id user@server-ip
PermitRootLogin no
sudo systemctl restart sshd
curl https://www.ssllabs.com/ssltest/analyze.html?d=example.com
sudo apt install fail2ban
Example /etc/fail2ban/jail.local:[sshd]
enabled = true
port = 2222
logpath = /var/log/auth.log
maxretry = 5
Restart Fail2Ban:sudo systemctl restart fail2ban
logwatch or journalctl to monitor server activity.sudo journalctl -u caddy
sudo apt install apparmor-utils
sudo aa-status