Loading…
Loading documentation...
Lock down sshd with drop-in cryptography, disable password auth, and apply systemd service sandboxing directives validated with systemd-analyze security.
Commands checked on 2026-11-23 with OpenSSH 9.6+, systemd 255+, Ubuntu 24.04, Rocky Linux 9.
An OpenSSH daemon hardened with modern post-quantum hybrid key exchange and key-only authentication, paired with isolated systemd service drop-ins verified by sshd -t and systemd-analyze security.
sudo-capable non-root user; see Administer Ubuntu, Debian, Rocky, and AlmaLinux servers cleanly.Never edit /etc/ssh/sshd_config inline when /etc/ssh/sshd_config.d/*.conf drop-ins are supported. Note that OpenSSH uses the first matching directive, so place overrides in a low-numbered drop-in or remove vendor cloud-init password overrides such as 50-cloud-init.conf:
sudo ls -la /etc/ssh/sshd_config.d/
sudo tee /etc/ssh/sshd_config.d/01-hardening.conf >/dev/null <<'EOF'
PermitRootLogin prohibit-password
PubkeyAuthentication yes
PasswordAuthentication no
PermitEmptyPasswords no
KbdInteractiveAuthentication no
MaxAuthTries 3
LoginGraceTime 20s
X11Forwarding no
AllowAgentForwarding no
ClientAliveInterval 300
ClientAliveCountMax 2
Ciphers chacha20-poly1305@openssh.com,aes256-gcm@openssh.com,aes128-gcm@openssh.com
EOF
Optionally enforce post-quantum hybrid key exchange on OpenSSH 9.x+ hosts (KexAlgorithms sntrup761x25519-sha512@openssh.com,curve25519-sha512,ecdh-sha2-nistp521) after verifying ssh -Q kex | grep sntrup761.
Never restart SSH without validating syntax and checking the merged effective configuration with -T:
sudo sshd -t
sudo sshd -T | grep -E '^(permitrootlogin|passwordauthentication|pubkeyauthentication|kbdinteractiveauthentication) '
Reload without breaking your current session (Ubuntu 24.04 socket-activated ssh.socket vs traditional ssh/sshd):
sudo systemctl reload ssh 2>/dev/null || sudo systemctl reload sshd
Systemd ships a built-in exposure auditor for running services:
systemd-analyze security nginx.service 2>/dev/null || systemd-analyze security ssh.service
Look for EXPOSED or UNSAFE scores (> 7.0) caused by full filesystem write access, missing capability bounding, or shared /tmp.
Create an override via systemctl edit <unit> (or write /etc/systemd/system/<unit>.service.d/hardening.conf) for application daemons such as Node.js web APIs or Caddy:
sudo mkdir -p /etc/systemd/system/webapp.service.d
sudo tee /etc/systemd/system/webapp.service.d/hardening.conf >/dev/null <<'EOF'
[Service]
NoNewPrivileges=true
ProtectSystem=strict
ProtectHome=true
PrivateTmp=true
PrivateDevices=true
ProtectKernelTunables=true
ProtectKernelModules=true
ProtectKernelLogs=true
ProtectControlGroups=true
RestrictSUIDSGID=true
LockPersonality=true
RestrictAddressFamilies=AF_INET AF_INET6 AF_UNIX
CapabilityBoundingSet=
ReadWritePaths=/var/lib/webapp
EOF
When using ProtectSystem=strict, grant write access explicitly via ReadWritePaths= (or StateDirectory=webapp) so the daemon can still persist uploads or SQLite/state files.
sudo systemctl daemon-reload
sudo systemctl restart webapp.service 2>/dev/null || true
systemd-analyze security webapp.service 2>/dev/null || true
Test key-only enforcement from an external workstation using verbose SSH debug flags without an identity loaded:
ssh -o PubkeyAuthentication=no -o PreferredAuthentications=password -v user@YOUR_SERVER_IP
OpenSSH should immediately reject with Permission denied (publickey) without prompting for a password.
sudo sshd -t, inspect /etc/ssh/authorized_keys, and fix /etc/ssh/sshd_config.d/.Port edits in sshd_config. Ubuntu 24.04 uses ssh.socket socket activation by default. Override [Socket] ListenStream= with sudo systemctl edit ssh.socket followed by sudo systemctl daemon-reload && sudo systemctl restart ssh.socket.Read-only file system or Permission denied after sandboxing. ProtectSystem=strict mounted its state directory read-only. Add the target directory to ReadWritePaths= or StateDirectory= and inspect exact denials via journalctl -u <unit> -n 40./etc/ssh/sshd_config untouched and keep site overrides cleanly separated in /etc/ssh/sshd_config.d/01-hardening.conf.ed25519 user keys (ssh-keygen -t ed25519 -C "ops@YOUR_DOMAIN") rather than legacy 2048-bit RSA keys.systemd-analyze security incrementally so NoNewPrivileges=true and ProtectHome=true never break unit scripts stored under /home.Every Servers Are Up virtual machine and container includes an integrated HTML5 browser-based SSH, RDP, and VNC console in your dashboard, default-off inbound firewall rules with per-IP allow-lists, and full programmatic control via REST API v1 and Model Context Protocol (MCP). Explore our Virtual Datacenter Plans or reach out to Servers Are Up Support.