---
title: "Ubuntu Linux Server"
description: "A guide on running an Ubuntu Linux server."
---

# Ubuntu Linux Server

This guide was written for Ubuntu Server 26.04 LTS.

For a VPS provider, I highly recommend [Hostinger](https://r.atomicspark.net/hostinger). I personally use their KVM 2 plan to host my website and a few other services:

- 2 vCPU cores
- 8 GB RAM
- 100 GB NVMe disk space
- 8 TB bandwidth

## Check for system updates

```shellsession
apt update && apt upgrade -y
```

If you see `Some sources can be modernized. Run 'apt modernize-sources' to do so`, run the following command:

```shellsession
apt modernize-sources
```

## Switch to a limited user account

You should switch to a limited user account as soon as possible.

### Delete or rename an existing user

Some platforms create a default limited user account (e.g., `ubuntu`) for you. For security reasons, you should delete or rename the account.

1. List all existing users:

   ```shellsession
   awk -F: '$3 >= 1000 && $3 < 65534 {print $1}' /etc/passwd
   ```

   And their home directories:

   ```shellsession
   ls -l /home
   ```

2. Either delete the existing user, group, and home directory:

   ```shellsession
   pkill -u ubuntu
   deluser --remove-home ubuntu
   delgroup ubuntu
   ```

   Or rename the existing user, group, and home directory, replacing `new_username` with your desired username:

   ```shellsession "new_username"
   usermod -l new_username ubuntu
   groupmod -n new_username ubuntu

   mv /home/ubuntu /home/new_username
   usermod -d /home/new_username -m new_username
   chown -R new_username:new_username /home/new_username
   ```

### Add a new user

1. Create a new user, changing `example_user`to your preferred user name:

   ```shellsession
   adduser example_user
   ```

2. Give the user `sudo` access to be able to run commands as `root`:

   ```shellsession
   adduser example_user sudo
   ```

## Disable root login

1. Open the sshd config file in a text editor:

   ```shellsession
   sudo nano /etc/ssh/sshd_config
   ```

2. Press <kbd>Ctrl+F</kbd>, type `PermitRootLogin`, and press Enter to find the setting.

3. Either comment it out, or change it to `prohibit-password` or `no`.

   The default is `prohibit-password`, which only allows SSH key based logins.

4. Press <kbd>Ctrl+X</kbd>, then <kbd>Y</kbd>, and finally <kbd>Enter</kbd> to save the file.

## Enable the firewall

1. Allow SSH through the firewall:

   ```shellsession
   sudo ufw allow "OpenSSH"
   ```

2. Enable logging:

   ```shellsession
   sudo ufw logging on
   ```

3. Start the firewall:

   ```shellsession
   sudo ufw enable
   ```

## Enable brute force protection

Use Fail2Ban to automatically block IP addresses with too many failed login attempts.

1. Install `fail2ban`:

   ```shellsession
   sudo apt install -y fail2ban
   ```

2. Check the current status of all jails (to see what's automatically protected):

   ```shellsession
   sudo fail2ban-client status --all
   ```
