Skip to content

Ubuntu Server First Steps

After spinning up a fresh Ubuntu server, there are a few critical steps to take before running any workloads. This guide covers system updates, SSH hardening, firewall setup, and basic security checks.

  • A fresh Ubuntu 22.04 LTS or 24.04 server
  • SSH access to the server
  • Root or sudo privileges
  • A local machine for generating SSH keys (if needed)

Connect to your server and update all packages to the latest versions.

Terminal window
sudo apt update
sudo apt upgrade -y
sudo apt autoremove -y

Verify the update completed successfully:

Terminal window
apt list --upgradable

If the output is empty, all packages are current.

Set a descriptive hostname for your server:

Terminal window
sudo hostnamectl set-hostname my-server

Verify the change:

Terminal window
hostnamectl

Set the timezone to match your location:

Terminal window
sudo timedatectl set-timezone America/New_York
timedatectl

If you don’t have an SSH key pair, generate one:

Terminal window
ssh-keygen -t ed25519 -C "your-email@example.com"

This creates ~/.ssh/id_ed25519 (private key) and ~/.ssh/id_ed25519.pub (public key).

Copy your public key to the server’s authorized_keys file:

Terminal window
ssh-copy-id -i ~/.ssh/id_ed25519.pub user@server-ip

Or manually:

Terminal window
mkdir -p ~/.ssh
echo "your-public-key-content" >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
chmod 700 ~/.ssh

Edit the SSH daemon configuration:

Terminal window
sudo nano /etc/ssh/sshd_config

Apply these changes:

/etc/ssh/sshd_config
#Port 22
Port 22
#PermitRootLogin prohibit-password
PermitRootLogin no
#PubkeyAuthentication yes
PubkeyAuthentication yes
#PasswordAuthentication yes
PasswordAuthentication no
#PermitEmptyPasswords no
PermitEmptyPasswords no
#X11Forwarding yes
X11Forwarding no

Restart SSH to apply changes:

Terminal window
sudo systemctl restart ssh

Enable and configure UFW (Uncomplicated Firewall):

Terminal window
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow 22/tcp
sudo ufw enable

Verify firewall status:

Terminal window
sudo ufw status verbose

Create a dedicated user account for daily work:

Terminal window
sudo useradd -m -s /bin/bash -G sudo myuser
sudo passwd myuser

Test login with the new user:

Terminal window
ssh myuser@server-ip

Prevent direct root login by locking the root account:

Terminal window
sudo passwd -l root

Verify the lock:

Terminal window
sudo passwd -S root

You should see “root L” (locked) in the output.

Run these commands to verify your setup:

CheckCommandExpected Result
System updatedapt list --upgradableEmpty output
Hostname sethostnamectlShows your hostname
SSH keys workingssh user@server-ipLogs in without password
Firewall activesudo ufw statusStatus: active
Root lockedsudo passwd -S rootShows “root L”

Check that SSH is running:

Terminal window
sudo systemctl status ssh

Restart if needed:

Terminal window
sudo systemctl restart ssh

If you changed SSH settings and can’t connect, use console access or recovery mode to fix /etc/ssh/sshd_config and restart SSH.

If you can’t connect after enabling UFW, add the SSH rule:

Terminal window
sudo ufw allow 22/tcp
sudo ufw reload

Once your server is hardened, you can:

  • Install Docker for running containerized services
  • Set up monitoring and log aggregation
  • Configure automated backups
  • Deploy your first application

See the Docker Compose Notes for the next step.