,

Initial Ubuntu 24.04 Server Setup: SSH Keys, UFW & Sudo User (2026)

Ubuntu 16.04 Server Setup

The first ten minutes after provisioning a fresh Ubuntu cloud VPS or installing a bare-metal home server from our Ubuntu 24.04 LTS Live Bootable USB Guide dictate the security posture of your entire infrastructure. Leaving default root password logins open to the public internet invites automated credential-stuffing botnets within seconds of your IP going live.

In Ubuntu 24.04 LTS (Noble Numbat), several core system behaviors have changed compared to older releases, most notably OpenSSH’s transition to systemd socket activation (ssh.socket) and modular /etc/ssh/sshd_config.d/ drop-in files. Below is the exact 5-step day-zero provisioning runbook before you apply our full Ubuntu Server Security Hardening Checklist.

Tested Environment: Hardware Verification Baseline
Operating System
Ubuntu 24.04.2 LTS Server (Linux Kernel 6.8)
OpenSSH Version
OpenSSH_9.6p1 Ubuntu-3ubuntu13 (ssh.socket enabled)
Firewall
UFW v0.36.2 (nftables backend)
Key Algorithm
Ed25519
Last Verified
November 2026

Key Takeaways

  • Ubuntu 24.04 ssh.socket Change: On Ubuntu 24.04, changing the SSH port requires overriding ssh.socket via sudo systemctl edit ssh.socket rather than editing /etc/ssh/sshd_config alone.
  • Use Modular Drop-In Configs: Place custom SSH directives inside /etc/ssh/sshd_config.d/99-initial-setup.conf so future openssh-server package upgrades never trigger interactive merge conflicts.
  • Keep Your Root Session Open While Testing: Never close your initial root terminal window until you have opened a second terminal tab and verified that your new sudo user can log in with their Ed25519 SSH key.

Day-Zero Provisioning Checklist: Default VPS vs Hardened Baseline

Every newly deployed cloud VPS ships with permissive defaults designed for initial login convenience rather than production security. The matrix below summarizes the five foundational changes we execute during the first ten minutes on a new Ubuntu 24.04 host.

System LayerDefault Cloud VPS StateInitial Setup Target StatePrimary Command / Config Path
Administrative IdentityDirect root login (UID 0)Unprivileged User in sudo Groupadduser deploy && usermod -aG sudo deploy
SSH AuthenticationPlaintext Password Auth EnabledEd25519 Public Key Only/etc/ssh/sshd_config.d/99-initial-setup.conf
SSH Daemon ManagementLegacy sshd.serviceUbuntu 24.04 ssh.socket + ssh.servicesudo sshd -t && sudo systemctl reload ssh
Inbound Network PerimeterAll Listening Ports Exposed (ufw inactive)Default Deny + Rate-Limited SSHsudo ufw limit 22/tcp && sudo ufw enable
Time & Swap ResilienceNo Swap on Cloud Images (OOM Risk)Chrony/NTP Sync + 2GB Swapfilefallocate -l 2G /swapfile

Step 1: Create a Non-Root Sudo User & Authorize Your Ed25519 SSH Key

Log into your new Ubuntu 24.04 server as root, update the APT package index, create a dedicated administrative user account, and copy your authorized SSH public key directly from root to the new user’s ~/.ssh/authorized_keys file with a single rsync command.

# 1. Update packages and create your administrative user (replace 'deploy' with your username)
apt update && apt upgrade -y
adduser deploy
usermod -aG sudo deploy

# 2. If you uploaded an SSH key to root during VPS creation, copy it to 'deploy' with correct ownership:
rsync --archive --chown=deploy:deploy ~/.ssh /home/deploy

(If you logged into root using a password and haven’t uploaded an SSH key yet, run ssh-keygen -t ed25519 on your local laptop followed by ssh-copy-id deploy@YOUR_SERVER_IP).

Step 2: Disable Root/Password SSH Logins, Enable UFW & Add a 2GB Swapfile

Once you confirm in a new terminal window that ssh deploy@YOUR_SERVER_IP logs in cleanly and sudo whoami returns root, lock down OpenSSH via a drop-in configuration file, enable UFW rate limiting, and allocate a 2GB swapfile so background APT updates never trigger an Out-of-Memory crash.

# 1. Create modular OpenSSH hardening drop-in file
sudo tee /etc/ssh/sshd_config.d/99-initial-setup.conf > /dev/null <<'EOF'
PermitRootLogin no
PasswordAuthentication no
KbdInteractiveAuthentication no
PubkeyAuthentication yes
MaxAuthTries 3
EOF

# 2. Validate SSH syntax and reload the daemon
sudo sshd -t && sudo systemctl reload ssh

# 3. Enable UFW with rate-limited SSH
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw limit 22/tcp comment 'SSH Rate Limit'
sudo ufw --force enable

# 4. Create a 2GB emergency swapfile with swappiness=10
sudo fallocate -l 2G /swapfile && sudo chmod 600 /swapfile
sudo mkswap /swapfile && sudo swapon /swapfile
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
echo 'vm.swappiness=10' | sudo tee /etc/sysctl.d/99-swappiness.conf && sudo sysctl --system

Frequently Asked Questions (FAQ)

Why does changing Port 2222 in sshd_config stop working on Ubuntu 24.04?

Ubuntu 24.04 uses systemd socket activation (ssh.socket) to listen for incoming SSH connections. To change your SSH port on Ubuntu 24.04, run sudo systemctl edit ssh.socket and add [Socket], ListenStream=, and ListenStream=2222, followed by sudo systemctl daemon-reload && sudo systemctl restart ssh.socket.

How do I fix Ubuntu Server installer hanging on Waiting for cloud-init during initial boot?

The cloud-init service hangs on bare-metal servers when no DHCP server responds on secondary Ethernet ports. Either plug in an active Ethernet cable before booting, or disable cloud-init after installation by running sudo touch /etc/cloud/cloud-init.disabled.

Comments

2 responses to “Initial Ubuntu 24.04 Server Setup: SSH Keys, UFW & Sudo User (2026)”

  1. Michał Wieczorek

    If it’s server most basic configuration then I would install iptables or ufw.