Security Is Foundational

Security

When you run your own server, there is no vendor security operations centre watching traffic for you. A private home setup presents a small target, yet a single exposed database port or weak SSH password can compromise the whole machine.

SSH Hardening

SSH is the main administrative doorway to any Linux box. Lock it down immediately after initial setup.

Key-Based Authentication Only

  1. Generate an Ed25519 key pair on your workstation:
ssh-keygen -t ed25519 -C "your-identifier"
  1. Copy the public key to the server:
ssh-copy-id user@server-ip
  1. Verify key login succeeds, then disable password logins and direct root SSH in /etc/ssh/sshd_config:
PasswordAuthentication no
PubkeyAuthentication yes
PermitRootLogin no
MaxAuthTries 3
  1. Reload the SSH daemon:
sudo systemctl restart sshd

Changing the Listening Port

Moving SSH from port 22 to a custom port cuts automated port-scanner log noise substantially. Treat this purely as log-noise reduction alongside key-only authentication, never as a substitute for strong access controls.

# /etc/ssh/sshd_config
Port 2222

Fail2ban: Ban Repeated Failed Logins

Fail2ban watches authentication logs and adds temporary firewall blocks against aggressive IP addresses:

sudo apt install fail2ban

Create /etc/fail2ban/jail.local:

[sshd]
enabled = true
port = 2222
maxretry = 3
findtime = 600
bantime = 3600

This blocks any IP failing three SSH attempts within ten minutes for one hour.

TLS Certificates

Every web app, even on a local network, should serve traffic over HTTPS using free certificates.

Let's Encrypt via Caddy (Automatic)

Caddy obtains and renews Let's Encrypt TLS certificates automatically whenever you define a domain block in your Caddyfile.

Let's Encrypt via Certbot (Manual or Standalone)

sudo apt install certbot
sudo certbot certonly --standalone -d yourdomain.com

Verify scheduled renewals with:

sudo certbot renew --dry-run

Internal-Only TLS

For services kept strictly inside your LAN without public DNS records, run an internal Certificate Authority such as Step-CA or mkcert.

Firewall Configuration

UFW (Uncomplicated Firewall)

sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow 2222/tcp    # SSH
sudo ufw allow 80/tcp      # HTTP
sudo ufw allow 443/tcp     # HTTPS
sudo ufw enable

Principle of Least Exposure

Do not open router ports for administrative consoles, NAS file shares, or databases. Reach internal tools over WireGuard or Tailscale instead.

Secrets Management

Keep database passwords and API tokens out of compose.yml and Git history:

  • Docker secrets: Native encrypted mounts in Swarm mode.
  • Restricted .env files: Store variables in .env with chmod 600 .env and add .env to .gitignore.
  • Dedicated secret managers: Tools such as Infisical or HashiCorp Vault for larger multi-host setups.

Two-Factor Authentication (2FA)

Enable TOTP or WebAuthn passkeys on every user-facing service that supports them (Nextcloud, Vaultwarden, Forgejo/Gitea, and SSH via pam_google_authenticator), using an authenticator app such as Aegis or Ente Auth rather than SMS codes.

Single Sign-On (SSO)

Once running ten or more web apps, adding an identity proxy gives unified login and 2FA enforcement in front of services that lack native authentication:

SolutionProtocolsSetup ComplexitySelf-Hosted
AutheliaOIDC, forward-authModerateYes
AuthentikOIDC, SAML, LDAPModerateYes
KeycloakOIDC, SAMLHighYes

Container Hardening

  • Avoid root inside containers: Set user: 1000:1000 where images allow it.
  • Use read-only root filesystems: Set read_only: true on compatible services.
  • Drop Linux capabilities: Apply cap_drop: [ALL] and add back only required capabilities.
  • Avoid privileged: true: Grant only specific device paths instead of full host privileges.
  • Scan images: Run trivy periodically to spot unpatched base-image CVEs.

Monitoring and Intrusion Alerts

  • Uptime Kuma: Service reachability and TLS certificate expiry alerts.
  • Grafana + Prometheus: System resource and disk health graphs.
  • CrowdSec: Collaborative log analysis blocking known abusive IPs.
  • Ntfy: Self-hosted push notifications for login and backup alerts.

Regular Security Maintenance

  • Weekly: Apply security updates and inspect Fail2ban / CrowdSec logs.
  • Monthly: Review open ports, verify disk usage, and test a backup restore.
  • Quarterly: Rotate sensitive tokens and audit user accounts.
  • Annually: Review network architecture, SSH keys, and recovery documentation.

Product links may include affiliate partnerships. See our affiliate disclosure for details.