Security hardening
Hardening is cumulative: each layer reduces the blast radius of the next mistake. Apply these controls in order and verify each one before moving on.
1. Operating system
bash
apt update && apt upgrade -y
apt install -y unattended-upgrades
dpkg-reconfigure --priority=low unattended-upgrades
timedatectl set-ntp trueKeep the kernel and OpenSSL current. Enable automatic security updates and reboot during a maintenance window when the kernel changes.
2. SSH
ini
# /etc/ssh/sshd_config
PermitRootLogin no
PasswordAuthentication no
PubkeyAuthentication yes
AllowUsers deploy
MaxAuthTries 3
ClientAliveInterval 300bash
systemctl restart sshTest key login in a second session before closing the first. Disabling passwords without a working key locks you out.
3. Firewall
bash
ufw default deny incoming
ufw default allow outgoing
ufw allow 80/tcp
ufw allow 443/tcp
ufw allow from 203.0.113.0/28 to any port 22 proto tcp
ufw allow from 203.0.113.0/28 to any port 8443 proto tcp
ufw enableRestrict the panel port to trusted addresses. If you host mail, open 25/465/587 deliberately and monitor them.
4. Panel exposure
- Put the admin panel behind a VPN or IP allow-list.
- Require two-factor authentication for every operator.
- Use named operator accounts; never share credentials.
- Set an idle session timeout and review active sessions monthly.
- Rotate API keys every 90 days and scope them narrowly.
5. TLS
- Issue certificates for every hostname, including aliases.
- Enable automatic renewal and monitor expiry.
- Enable HSTS only after every subdomain supports HTTPS.
- Disable TLS 1.0/1.1 and weak ciphers at the edge.
nginx
ssl_protocols TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers off;
ssl_session_cache shared:SSL:10m;6. Application isolation
| Control | Recommendation |
|---|---|
| Container per account | Keep enabled; do not run tenants in the host namespace |
| File ownership | Site user owns site files; never 777 |
| Database users | One user per application, least privilege |
| Secrets | Outside the document root, readable only by the site user |
| Disabled functions | Block exec, shell_exec, passthru unless required |
ini
; Per-site php.ini fragment
disable_functions = exec,passthru,shell_exec,system,proc_open,popen
open_basedir = /home/acme/sites/app.example.com:/tmp7. Mail security
- Publish SPF, DKIM and DMARC.
- Rate-limit outbound mail per account.
- Block port 25 outbound from application containers unless explicitly allowed.
- Monitor authentication failures and unusual sending patterns.
8. Backups
- Keep one copy off the server.
- Encrypt remote backups.
- Test a restore quarterly.
- Protect backup credentials separately from panel credentials.
- Alert on failed jobs, not just on success.
9. Monitoring and alerts
| Signal | Threshold |
|---|---|
| CPU | > 85% for 10 minutes |
| Memory | > 90% for 5 minutes |
| Disk | > 85% used |
| Failed logins | > 20 per IP per hour |
| Certificate expiry | < 14 days |
| Backup failure | Any |
| Outbound mail | > 3× baseline |
Route alerts to a channel someone reads. An unread alert is the same as no alert.
10. Incident readiness
- Keep an offline copy of recovery codes.
- Document who can reboot, restore and rotate credentials.
- Practise one restore and one key rotation per quarter.
- Preserve logs before rebuilding a compromised host.
Review checklist
- [ ] OS and panel patched, NTP enabled
- [ ] SSH key-only, root login disabled
- [ ] Firewall default-deny with explicit allows
- [ ] Panel and admin API restricted by IP or VPN
- [ ] 2FA enforced, API keys scoped and rotated
- [ ] TLS valid everywhere, HSTS after verification
- [ ] Least-privilege database users, no
777 - [ ] Offsite encrypted backups with tested restores
- [ ] Alerts wired and acknowledged