Keep the System Updated
Unpatched software is the most common entry point for attackers. Apply security updates as soon as they are available.unattended-upgrades installs security patches automatically in the background. The dpkg-reconfigure command walks you through the initial configuration interactively. Review /etc/apt/apt.conf.d/50unattended-upgrades to fine-tune which update categories are applied automatically.
Harden SSH
SSH is the most commonly attacked service on internet-facing servers. Tighten its configuration by editing/etc/ssh/sshd_config:
Setting
PasswordAuthentication no means you must have your SSH public key installed in ~/.ssh/authorized_keys before restarting sshd. Locking yourself out of a cloud server without password auth and without a key is a painful recovery experience.Fail2ban: Brute-Force Protection
Fail2ban monitors log files and automatically bans IP addresses that show signs of automated attacks, such as repeated failed SSH login attempts.Create a local configuration
Never edit This bans an IP for one hour after 3 failed attempts within 10 minutes.
/etc/fail2ban/jail.conf directly — it will be overwritten on upgrades. Create /etc/fail2ban/jail.local instead:Configure the Firewall
Useufw (Uncomplicated Firewall) to restrict network access to only the services you intentionally expose.
Minimize Running Services
Every running service is a potential attack surface. Disable anything you do not need.Audit Logging with auditd
auditd records system calls and file access events to a tamper-evident log, giving you a trail of who did what on the system.
-w /etc/passwd -p wa rule watches the passwd file for write (w) and attribute-change (a) events. The -k flag attaches a searchable key to the rule so you can retrieve matching events with ausearch -k passwd_changes.
Rules added with
auditctl are temporary and lost on reboot. To make them permanent, add them to /etc/audit/rules.d/audit.rules instead. For example: -w /etc/passwd -p wa -k passwd_changes. Run sudo augenrules --load to apply the file without rebooting.File Integrity with AIDE
AIDE (Advanced Intrusion Detection Environment) builds a database of file checksums and attributes, then alerts you when files change unexpectedly.aide --check regularly — ideally as a cron job — and compare its output against your baseline. Unexpected changes to binaries, configuration files, or libraries can indicate a compromise.
sudo Best Practices
Edit safely
Always use
sudo visudo to edit the sudoers file. It validates the syntax before saving, preventing a broken sudoers file from locking you out of sudo entirely.Least privilege
Grant users only the specific commands they need, not blanket
ALL=(ALL) ALL. Use NOPASSWD only for specific, low-risk commands in automation contexts./var/log/auth.log and the systemd journal by default. Review this log periodically for unexpected privilege escalation.