Linux · Security hardening · SSH · UFW · TLS 1.3 · Docker

Linux server hardening checklist: SSH bastion, UFW, TLS, and Docker

By Naufal Randi Aldiansyah · · 2 min read

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 3

Run 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.com

2. 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 enable

One 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

5. Patch and watch