Ubuntu & Debian Server Hardening: A Practical First-Day Checklist
Lock down a fresh Ubuntu or Debian home server step by step: Ed25519 SSH keys, disabling root and passwords, automatic security updates, and port checks.
On this page
- 1. Confirm a Non-Root Sudo User
- 2. Generate and Deploy an Ed25519 SSH Key Pair
- 3. Lock Down SSH Using a Modular Drop-In File
- 4. Enable Automatic Security Updates (unattended-upgrades)
- 5. Audit Listening Services and Disable Unneeded Daemons
- Troubleshooting Common Hardening Issues
- 1. Password login still works even with 99-hardening.conf
- 2. Permissions 0644 for '~/.ssh/id_ed25519' are too open
- 3. Locked out after changing AllowUsers or SSH config
- 4. /boot hits 100% full after months of unattended-upgrades
Basic Ubuntu and Debian Server Hardening
Secure SSH access, enable automatic security patches, and verify listening services on a new Linux home server.
Estimated time: PT20M
Create a non-root sudo user
Add a standard admin account with sudo privileges instead of logging in directly as root.
Generate and install an Ed25519 SSH key
Generate a local ssh-keygen -t ed25519 key pair and copy the public key to the server with ssh-copy-id.
Harden sshd via a drop-in config
Disable PermitRootLogin and PasswordAuthentication in /etc/ssh/sshd_config.d/99-hardening.conf and test with sudo sshd -t.
Enable unattended security upgrades
Install and configure unattended-upgrades so critical kernel and OpenSSL CVEs patch automatically.
Audit listening network ports
Inspect active sockets with sudo ss -tulpn and disable unused services.
Every new Linux server starts with two competing goals: staying convenient enough that you actually maintain it, and closing the obvious doors that automated scanners or misbehaving devices on your network look for first. You do not need SELinux enterprise playbooks or kernel tuning for a homelab. Five concrete changes—a non-root sudo user, Ed25519 SSH keys, locked-down sshd, automatic security patches, and a clean port audit—remove over 90% of day-one risk in 20 minutes while keeping resource overhead at 0 MB of extra RAM.
This checklist assumes you just finished our first 5 things after installing Linux guide on Ubuntu 24.04 LTS or Debian 12. Once you finish here, pair it with our UFW and Fail2ban guide to filter traffic at the firewall level.
1. Confirm a Non-Root Sudo User
Some VPS providers and minimal Debian images drop you straight into a root shell. Operating day-to-day as root turns any typo into a system-wide outage and gives every remote SSH brute-force attempt a known username to target.
If you do not already have a standard admin account, create one (sysadmin here—swap for your name) and add it to the sudo group:
sudo adduser sysadminsudo usermod -aG sudo sysadminTest sudo from that user before touching SSH settings:
su - sysadminsudo whoamiIt should print root. Never give that user a weak dictionary password—use our password generator to generate at least a 16-character passphrase for sudo elevation.
2. Generate and Deploy an Ed25519 SSH Key Pair
On your laptop or workstation (not on the server), generate an Ed25519 key pair:
ssh-keygen -t ed25519 -C "laptop-homelab"Line by line:
-t ed25519picks modern elliptic-curve cryptography instead of older 2048-bit RSA. Keys generate in milliseconds and fit on one short line.-C "laptop-homelab"attaches a human-readable comment at the end of.pubso you recognize which computer owns each key six months from now.- Press Enter to accept the default path (
~/.ssh/id_ed25519), and enter a strong passphrase when prompted. Even if someone copies your laptop’s~/.sshfolder, they cannot use the private key without that passphrase.
Copy the public key to your server (192.168.1.20 in this example):
ssh-copy-id -i ~/.ssh/id_ed25519.pub sysadmin@192.168.1.20Verify permissions on the server—OpenSSH silently rejects keys if ~/.ssh or authorized_keys can be written by anyone else (double-check octal values in our chmod calculator):
chmod 700 ~/.sshchmod 600 ~/.ssh/authorized_keysNow open a brand-new terminal tab and log in:
ssh sysadmin@192.168.1.20Confirm it asks for your key passphrase (or logs straight in via ssh-agent), not the server user’s Linux password.
3. Lock Down SSH Using a Modular Drop-In File
Instead of editing the main /etc/ssh/sshd_config file—which causes merge prompts during OS upgrades—modern Ubuntu (22.04/24.04) and Debian (12+) read drop-in files in /etc/ssh/sshd_config.d/ alphabetically. Keep your original sshd_config untouched and create 99-hardening.conf (or 01-hardening.conf, see Troubleshooting below about cloud-init overrides):
sudo nano /etc/ssh/sshd_config.d/01-hardening.confPaste these settings:
PermitRootLogin noPasswordAuthentication noKbdInteractiveAuthentication noPubkeyAuthentication yesMaxAuthTries 3X11Forwarding noAllowUsers sysadminWhat every single line enforces:
PermitRootLogin noblocks directrootlogins entirely, even with SSH keys. Admin tasks go throughsysadmin+sudo.PasswordAuthentication noandKbdInteractiveAuthentication nostop automated password-guessing bots cold—without a matching key inauthorized_keys, the server drops the attempt immediately.PubkeyAuthentication yesguarantees key authentication stays explicitly enabled.MaxAuthTries 3disconnects clients after three failed authentication attempts per TCP connection instead of letting them probe dozens of keys.X11Forwarding noturns off graphical X11 forwarding you never need on a headless server.AllowUsers sysadminrestricts SSH solely to your named admin user (if you add a dedicated backup user later, append it separated by a space:AllowUsers sysadmin resticbackup).
Before restarting the daemon, validate the syntax:
sudo sshd -tIf sshd -t returns zero output (no errors), reload the service while keeping your existing SSH session open:
sudo systemctl reload ssh(Note: Debian uses ssh; older tutorials occasionally reference sshd, and Ubuntu 24.04 uses socket activation ssh.socket, which systemctl reload ssh handles cleanly.)
Immediately open a second terminal window on your laptop and confirm:
ssh sysadmin@192.168.1.20succeeds with your key.ssh -o PubkeyAuthentication=no sysadmin@192.168.1.20fails cleanly withPermission denied (publickey).
4. Enable Automatic Security Updates (unattended-upgrades)
Critical bugs in openssl, openssh-server, curl, or the Linux kernel appear year-round. Waiting four months until you remember sudo apt update leaves known CVEs sitting open on your box.
Install unattended-upgrades:
sudo apt update && sudo apt install -y unattended-upgrades apt-listchangessudo dpkg-reconfigure -plow unattended-upgradesChoose Yes when prompted. Then inspect /etc/apt/apt.conf.d/50unattended-upgrades to make two smart adjustments:
sudo nano /etc/apt/apt.conf.d/50unattended-upgradesEnsure security origins are active (enabled by default on Ubuntu/Debian) and remove unused kernel packages automatically so /boot never fills up on small SSDs:
Unattended-Upgrade::Remove-Unused-Kernel-Packages "true";Unattended-Upgrade::Remove-Unused-Dependencies "true";Unattended-Upgrade::Automatic-Reboot "false";Setting Automatic-Reboot "false" keeps your media server or Immich instance from restarting unexpectedly mid-stream; instead, check for /var/run/reboot-required once a week or schedule a monthly 04:00 AM maintenance window. Test a dry run to confirm zero syntax errors:
sudo unattended-upgrade --dry-run --debugExpect an exit status cleanly listing checked origins and taking ~2–5 seconds.
5. Audit Listening Services and Disable Unneeded Daemons
Fresh installs—especially old desktop-turned-server setups or prebuilt SBC images—sometimes leave CUPS printer daemons (631), Avahi mDNS (5353), or RPC portmapper (111) listening on 0.0.0.0. Every unnecessary daemon increases memory use and attack surface.
Inspect every listening TCP and UDP socket:
sudo ss -tulpnLook closely at the Local Address:Port column:
127.0.0.1:...or127.0.0.53:53(systemd-resolved) is local loopback only—invisible from the network. Safe.0.0.0.0:22or*:22issshdlistening on all interfaces—expected (unless you bind SSH strictly to your LAN or Tailscale IP later).0.0.0.0:631(cupsd) or0.0.0.0:111(rpcbind) on a headless server with no shared USB printer or NFS server can be stopped and masked right away:
sudo systemctl disable --now cups.service rpcbind.serviceCheck default port numbers whenever an unfamiliar socket appears in ss -tulpn.
Troubleshooting Common Hardening Issues
1. Password login still works even with 99-hardening.conf
Ubuntu cloud and Proxmox cloud-init images frequently create /etc/ssh/sshd_config.d/50-cloud-init.conf containing PasswordAuthentication yes. In OpenSSH, the first matching directive wins, not the last! Because 50- loads before 99-, 50-cloud-init.conf overrides 99-hardening.conf. Naming our drop-in 01-hardening.conf fixes this, or edit 50-cloud-init.conf directly and verify with:
sudo sshd -T | grep -E "passwordauthentication|permitrootlogin"Both lines must output no.
2. Permissions 0644 for '~/.ssh/id_ed25519' are too open
If you copied your private key onto another workstation and OpenSSH refuses to read it, your private key is readable by group/others. Lock it back down locally with chmod 600 ~/.ssh/id_ed25519 (only owner read/write).
3. Locked out after changing AllowUsers or SSH config
Never close your initial root/password SSH session until a second window successfully logs in. If you did get locked out on a home server, plug in a keyboard and monitor (physical console is unaffected by SSH config), log in locally, run sudo sshd -t to find the typo, fix /etc/ssh/sshd_config.d/01-hardening.conf, and run sudo systemctl restart ssh.
4. /boot hits 100% full after months of unattended-upgrades
If you did not enable Remove-Unused-Kernel-Packages "true", old Linux kernel headers pile up in /boot. Free them safely anytime with:
sudo apt autoremove --purge -yFrequently Asked Questions
Is Ed25519 better than RSA 4096 for home server SSH keys?
Yes. Ed25519 keys are shorter (68 characters for the public key), faster to verify, immune to padding oracle issues, and provide cryptographic strength comparable to RSA-3072 or RSA-4096. Every modern OpenSSH client and server supports Ed25519 out of the box.
What happens if I disable SSH passwords before confirming my key works?
You lock yourself out of remote SSH access immediately. Always keep one active SSH session open as a safety net while testing your key login from a second terminal window before closing anything.
Can unattended-upgrades break Docker containers overnight?
Automatic security updates only patch packages from your distro's -security repository by default, not major OS versions. However, enabling automatic midnight reboots can briefly interrupt running services, so check whether you prefer manual reboots or scheduled downtime.
Do I still need SSH hardening if my home server is not forwarded on my router?
Yes. Every device on your LAN (smart TVs, guests' phones, IoT plugs, compromised laptops) shares the local network with your server. Defense in depth ensures local lateral movement cannot guess weak credentials.