Summary of Security Measures to Take for a Home Server

Secure SSH Management with Cloudflare Tunnel
Secure SSH Management with Cloudflare Tunnel

Cloudflare Trunnel

Recently, TailScale has become more popular. Either is fine.
Set up an environment where you can log in via SSH without opening port 22 from the internet, and close port 22.

Firewall Settings

If you use Cloudflare Tunnel or TailScale, it’s okay to keep port 22 closed from external sources.

# Install UFW
sudo apt update
sudo apt install -y ufw

# Basic policies
sudo ufw default deny incoming
sudo ufw default allow outgoing

# Allow only HTTPS
sudo ufw allow 443/tcp

# Logging settings
sudo ufw logging low

# Enable
sudo ufw enable

# Check settings
sudo ufw status verbose
sudo ufw status numbered

SSH Connection Security Enhancements

Edit /etc/ssh/sshd_config
Modify the following:

# Users allowed to log in via SSH (replace hogetara with your username)
AllowUsers hogetara

# Disable root login
PermitRootLogin no

# Allow public key authentication
PubkeyAuthentication yes

# Disable password authentication
PasswordAuthentication no
  • Disable password authentication and root login.
  • Allow only public key authentication for specific users.

Run the following command for verification:

sudo grep -RnE '^[[:space:]]*(AllowUsers|AllowGroups|DenyUsers|PermitRootLogin|PubkeyAuthentication|PasswordAuthentication|Match)\b' /etc/ssh/sshd_config /etc/ssh/sshd_config.d/

If the output is as follows, it’s correct:

/etc/ssh/sshd_config:54:PermitRootLogin no
/etc/ssh/sshd_config:59:PubkeyAuthentication yes
/etc/ssh/sshd_config:78:PasswordAuthentication no
/etc/ssh/sshd_config:149:AllowUsers hogetara(Your SSH login username)

Restart sshd for verification:

sudo systemctl reload ssh

If you use Windows on your local PC, you can also implement SSH key protection with TPM to prevent key leaks, which further restricts SSH login to your own PC for enhanced security.

Automatic APT Package Updates

For home servers, we perform aggressive upgrades and reboots. For Ubuntu 26.04 LTS, it’s recommended to use unattended-upgrades and systemd timers.

This guide assumes a server managed via Cloudflare Tunnel + WARP, with the following schedule:

Time Process
Daily 03:00 Equivalent to apt-get update
Daily 03:10 Automatically install security updates
After updates Reboot only if necessary
Others Continue running without reboot

1. Install unattended-upgrades

sudo apt update
sudo apt install -y unattended-upgrades

2. Configure Automatic Updates and Reboots

Create a new configuration file:

sudo vi /etc/apt/apt.conf.d/99-local-auto-upgrades

Add the following content:

// Update package lists daily
APT::Periodic::Update-Package-Lists "1";

// Automatically update packages daily
APT::Periodic::Unattended-Upgrade "1";

// Reboot automatically if needed
Unattended-Upgrade::Automatic-Reboot "true";

// Reboot even if users are logged in via SSH
Unattended-Upgrade::Automatic-Reboot-WithUsers "true";

// Reboot immediately after updates
Unattended-Upgrade::Automatic-Reboot-Time "now";

With this configuration, the system will reboot after updates if necessary. The need for a reboot is determined by Ubuntu’s /run/reboot-required.

3. Schedule apt-get update at 03:00 Daily

sudo systemctl edit apt-daily.timer

Add the following to the editor:

[Timer]
OnCalendar=
OnCalendar=*-*-* 03:00:00
RandomizedDelaySec=0
AccuracySec=1s
Persistent=false

The empty line for OnCalendar= is required to clear existing timer settings. Persistent=false prevents additional execution after server startup if the server was offline at 03:00.

4. Schedule Automatic Upgrades at 03:10

sudo systemctl edit apt-daily-upgrade.timer

Add the following:

[Timer]
OnCalendar=
OnCalendar=*-*-* 03:10:00
RandomizedDelaySec=0
AccuracySec=1s
Persistent=false

With this setup, the update installation process starts at 03:10 daily. If the 03:00 package list update takes longer, the installation may be delayed.

5. Enable the Configuration

sudo systemctl daemon-reload

sudo systemctl enable --now apt-daily.timer
sudo systemctl enable --now apt-daily-upgrade.timer

sudo systemctl restart apt-daily.timer
sudo systemctl restart apt-daily-upgrade.timer

6. Verify

To check the execution history:

sudo tail -n 100 /var/log/unattended-upgrades/unattended-upgrades.log
© 2025 Hiroe Tech Notes. All rights reserved.

Comments

No comments yet.