Security Hardening Checklist
Advanced15 minTrending
Audit and harden a Linux server by checking SSH configuration, open ports, running services, and filesystem permissions.
Prerequisites
- -Linux shell access
- -Root or sudo access
Steps
1
Audit SSH configuration
Check for insecure SSH settings.
$ sudo sshd -T 2>/dev/null | grep -E 'permitrootlogin|passwordauthentication|pubkeyauthentication|port '
Best practice: PermitRootLogin no, PasswordAuthentication no, PubkeyAuthentication yes.
2
Check for open ports
See all ports listening for incoming connections.
$ ss -tlnp
Close any ports you do not recognize or need. Each open port is a potential attack vector.
3
Find world-writable files
Locate files that any user can modify, which can be a security risk.
$ sudo find / -xdev -type f -perm -o+w -not -path '/proc/*' -not -path '/sys/*' 2>/dev/null | head -20
4
Check for users with empty passwords
Find accounts that have no password set.
$ sudo awk -F: '($2 == "") {print $1}' /etc/shadow
Accounts with empty passwords are a critical security risk. Set a password or lock these accounts immediately.
5
Check for pending security updates
See if there are security patches available.
$ apt list --upgradable 2>/dev/null | grep -i security || yum check-update --security 2>/dev/null || echo 'Check your package manager'
Full Script
FAQ
Discussion
Loading comments...