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.
ssh.socket enabled)Key Takeaways
- Ubuntu 24.04
ssh.socketChange: On Ubuntu 24.04, changing the SSH port requires overridingssh.socketviasudo systemctl edit ssh.socketrather than editing/etc/ssh/sshd_configalone. - Use Modular Drop-In Configs: Place custom SSH directives inside
/etc/ssh/sshd_config.d/99-initial-setup.confso futureopenssh-serverpackage upgrades never trigger interactive merge conflicts. - Keep Your Root Session Open While Testing: Never close your initial
rootterminal window until you have opened a second terminal tab and verified that your newsudouser 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 Layer | Default Cloud VPS State | Initial Setup Target State | Primary Command / Config Path |
|---|---|---|---|
| Administrative Identity | Direct root login (UID 0) | Unprivileged User in sudo Group | adduser deploy && usermod -aG sudo deploy |
| SSH Authentication | Plaintext Password Auth Enabled | Ed25519 Public Key Only | /etc/ssh/sshd_config.d/99-initial-setup.conf |
| SSH Daemon Management | Legacy sshd.service | Ubuntu 24.04 ssh.socket + ssh.service | sudo sshd -t && sudo systemctl reload ssh |
| Inbound Network Perimeter | All Listening Ports Exposed (ufw inactive) | Default Deny + Rate-Limited SSH | sudo ufw limit 22/tcp && sudo ufw enable |
| Time & Swap Resilience | No Swap on Cloud Images (OOM Risk) | Chrony/NTP Sync + 2GB Swapfile | fallocate -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)”
If it’s server most basic configuration then I would install iptables or ufw.
@@disqus_U7hRRLBzgf:disqus Thanks for your comment. I’ve added the firewall bits.