Skip to content
Back to Series Homelab from Scratch
Security

Hardening Homelab Server Security: A Complete Guide

Secure your homelab server with essential hardening steps from SSH key authentication to service isolation and automated updates using this practical checklist.

A
Alif Afriza Author
· · 5 min read
Hardening Homelab Server Security: A Complete Guide

A homelab usually doesn’t attack popular sites, but that doesn’t mean it’s free from threats. Your server still has a public IP (if it’s used for external access), uses SSH, and runs several services. All of these are attack surfaces where bots try to log in randomly throughout the day.

Hardening is about reducing that surface: turning off what isn’t needed, making unauthorized access difficult, and ensuring every component is always up to date.

1. SSH Login with Keys, Disable Passwords

The most impactful security change you can make is blocking password-based SSH login, because passwords are the target of brute force bots. Replace them with a public key.

# On your local computer, generate a key (if you don't have one)
ssh-keygen -t ed25519 -C "home-server"

# Copy the key to the server
ssh-copy-id user@server-ip

Then on the server, edit /etc/ssh/sshd_config:

# Disable password login
PasswordAuthentication no
PubkeyAuthentication yes
PermitRootLogin no

# Restrict which users can log in (replace with your username)
AllowUsers alif

Don’t forget to restart SSH: sudo systemctl restart sshd. Make sure the connection you’re using already has a working key, so you don’t lock yourself out. Safe tip: test from another terminal before closing your current session.

2. Install fail2ban

fail2ban monitors failed login attempt logs and temporarily blocks IPs after several attempts. This is very effective for SSH exposed to the internet.

sudo apt install fail2ban -y

# Create a local configuration
sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local

In jail.local:

[sshd]
enabled = true
maxretry = 5
bantime = 3600
findtime = 600

Then sudo systemctl restart fail2ban. Monitor with sudo fail2ban-client status sshd; you’ll see how many IPs have been blocked within a few days.

3. Automatic Updates

The most exploited vulnerabilities that can appear are ones that have already been patched, but whose updates were never applied. Eliminate this tedious work with autoupdate.

sudo apt install unattended-upgrades -y

# Enable via the config file
sudo dpkg-reconfigure --priority=low unattended-upgrades

Make sure the schedule is running: sudo systemctl status unattended-upgrades. For large manual updates, perform them on a schedule that suits you.

4. Firewall: The First Rule is Deny

Create a firewall policy that closes all ports except the ones actually in use.

# UFW on Ubuntu
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow ssh
sudo ufw allow from 192.168.1.0/24 to any port 3000  # example: grafana internal only
sudo ufw enable

The “deny by default” principle is safer than “open then close”. Services that shouldn’t be visible from the internet stay closed until you actually open them.

5. Disable Unused Services

Every running service is code that can contain bugs. Inspect what’s running and disable anything with no clear purpose.

# View active services
systemctl list-units --type=service --state=running

# View open ports
ss -tulpn

Additionally: set up log rotation (logrotate) so logs don’t bloat, and enable timedatectl so all servers share a consistent time zone for reading logs.

6. Least Privilege for Users and Docker

Don’t run everything as the root user. Create dedicated users for each task and container with the minimum necessary privileges.

# Create a dedicated service user without sudo rights
sudo useradd --create-home --shell /bin/bash service-user
sudo -u service-user command...

For Docker, avoid running images as root when it isn’t necessary. Some modern images already provide a user option. Example compose:

services:
  app:
    image: example/app:latest
    user: "1000:1000"   # container runs as a non-root user
    read_only: true     # container file system is read-only
    tmpfs:
      - /tmp
    security_opt:
      - no-new-privileges:true

The combination of read_only, tmpfs, and no-new-privileges means that even a container that gets exploited has limited room to maneuver.

7. External Access: Tunnel or VPN, Not Public Ports

If you need access from outside your home, don’t open application ports to the internet. Use one of two methods:

  • WireGuard/Tailscale: a private virtual network. Secure services remain invisible to the public.
  • Reverse tunnel (e.g. Cloudflare Tunnel): an intermediary that forwards connections to the server without opening public ports.

Both approaches drastically reduce the attack surface, and have been covered in more detail in Part 6: Access from Anywhere.

8. Verify the Hardening Results

A few quick ways to check the server’s condition:

# Update the status of all packages
apt list --upgradable

# Audit SSH settings
sudo sshd -T | grep -E 'passwordauthentication|permitrootlogin'

# Test open ports from inside
sudo nmap -sT -p- localhost | grep open

Keep a record of the changes you make (for example in a SECURITY.md file in the homeserver repo). Documentation lets you add or roll back changes with peace of mind.

Summary

Hardening isn’t a single action, but a commitment: key-based login, brute force blocking, automatic updates, deny-by-default firewall, least privilege, and external access through a tunnel/VPN. Each layer narrows the attack gap further.

The server is now secure and monitored (Part 10). The final step of this series is virtualizing everything properly on a single piece of Proxmox hardware, so that each service is isolated and maintenance becomes easy. Continue to Part 12: Proxmox VE.

Open for Contributors

Your ideas deserve to be read by thousands of people.

ByteNesia is built for everyone. If you have experience, tutorials, or opinions about technology, write and share them here. Your name will be credited as a contributor.

Write anything: tool reviews, homelab tutorials, security tips, or your tech stories.

Discussion & Comments