First Steps After Installing Ubuntu Server 24.04

Hey folks! Congratulations on setting up your Ubuntu Server 24.04 virtual private server (VPS)! To ensure a secure and efficient server environment, let’s perform some essential initial configurations.

1. Initial SSH Login and System Updates

ssh root@<your_server_ip>

You’ll be prompted for the root password you set during the installation.

sudo apt update
sudo apt upgrade

2. Create a Non-Root Sudo User

adduser <your_username>
usermod -aG sudo <your_username>
ssh <your_username>@<your_server_ip>

From now on, use this user for daily tasks and avoid using the ‘root’ account directly.

3. Secure SSH Access with Key-Based Authentication

ssh-keygen

Follow the prompts, providing a strong passphrase if desired.

ssh-copy-id <your_username>@<your_server_ip>
ssh <your_username>@<your_server_ip>

If you can log in successfully without being prompted for a password, your SSH key setup is working correctly.

sudo nano /etc/ssh/sshd_config

Find and change the following:

PasswordAuthentication no
ChallengeResponseAuthentication no

4. Disable Root SSH Login

Important Security Step: To further enhance security, prevent the root user from logging in directly via SSH. In the same sshd_config file, find and change:

PermitRootLogin no

Check for Overrides: In Ubuntu Server 24.04, a file named /etc/ssh/sshd_config.d/50-cloud-init.conf may override these settings. If it exists, open it with sudo nano /etc/ssh/sshd_config.d/50-cloud-init.conf and comment out (add a # at the beginning) or change the line related to PasswordAuthentication and PermitRootLoginif they are present.

sudo systemctl restart sshd

5. Set Up a Firewall with UFW

sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow ssh
sudo ufw enable
sudo ufw status

This will typically display output similar to the following:

Status: active

To                         Action      From
--                         ------      ----
22/tcp                     ALLOW       Anywhere                  
Anywhere                   ALLOW       Anywhere                   (v6) 

This output indicates that the firewall is active, allowing incoming SSH connections on port 22 (both IPv4 and IPv6),while denying all other incoming traffic. If you’ve added other rules, they will also be listed here.

6. Install and Configure NTP for Time Synchronization

sudo apt install ntp
timedatectl status
ntpq -p

Next Steps

You’ve laid a solid foundation for a secure Ubuntu Server environment. Consider these additional steps:

Let me know if you have any other questions!