Linux server hardening checklist: SSH bastion, UFW, TLS, and Docker
At Hashmicro I hardened multi-tenant Linux servers: SSH access policies, bastion host isolation, TLS 1.3, UFW rules, and Docker container baselines. This is that baseline as a checklist. Keep console access ready before you start, and do SSH and the firewall first.
1. SSH: keys only, through one door
# /etc/ssh/sshd_config.d/hardening.conf
PermitRootLogin no
PasswordAuthentication no
KbdInteractiveAuthentication no
AllowGroups ssh-users
MaxAuthTries 3Run sshd -t to validate, then reload the service, and keep your current session open until a second login works. Application servers accept SSH only from the bastion. Clients reach them with a jump host.
# ~/.ssh/config
Host app-*
ProxyJump bastion.example.com2. Firewall: deny by default
ufw default deny incoming
ufw default allow outgoing
ufw allow from 10.0.0.5 to any port 22 proto tcp # bastion only
ufw allow 80,443/tcp
ufw enableOne trap: Docker publishes ports by writing its own iptables rules, and those bypass UFW. A container started with -p 8080:8080 is public even when UFW says the port is closed. Publish on loopback with -p 127.0.0.1:8080:8080 and put nginx in front.
3. TLS 1.2 and 1.3 only
ssl_protocols TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers off;
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;If every client you serve is modern, drop to TLSv1.3 alone. Renew certificates automatically and alert on expiry, because an expired certificate is an outage.
4. Containers: least privilege
docker run --read-only --tmpfs /tmp \
--cap-drop ALL --security-opt no-new-privileges \
--user 10001:10001 --memory 512m --pids-limit 200 \
-p 127.0.0.1:8080:8080 myapp:1.4.2- Pin image tags to a version.
latestmakes a rollback impossible to reason about. - Scan images in CI before they reach a server.
- Never mount the Docker socket into an application container. It is root on the host.
5. Patch and watch
- Enable
unattended-upgradesfor security updates. - Ship authentication logs to a central place and alert on new sudo users and on logins outside the bastion.
- Run
lynis audit systemeach quarter and compare the result against the CIS benchmark for your distribution.