Back to blog
Oct 04, 2024
3 min read

Basic Configuration for Ubuntu VPS

A guide to the essential steps you need to take to set up your Ubuntu VPS for the first time.

Introduction

Setting up an Ubuntu VPS for the first time requires some basic configurations to ensure security, performance, and usability. This guide will walk you through the essential steps to configure your Ubuntu VPS right after deployment.

Prerequisites

  • An Ubuntu VPS (preferably Ubuntu 22.04).
  • Root or sudo user access to the VPS.

Step 1: Update and Upgrade the System

It’s important to start by updating the package list and upgrading installed packages to ensure that your system has the latest security patches and software versions.

sudo apt update
sudo apt upgrade -y

Step 2: Create a New User

For security reasons, it’s recommended not to use the root account for day-to-day operations. Instead, create a new user with sudo privileges.

sudo adduser your_username
sudo usermod -aG sudo your_username

Now you can switch to the new user:

su - your_username

Step 3: Set Up a Firewall (UFW)

Securing your VPS with a firewall is crucial. Ubuntu comes with UFW (Uncomplicated Firewall), which you can configure to only allow necessary traffic.

First, allow SSH (you can customize the port if you changed it):

sudo ufw allow OpenSSH

Enable the firewall:

sudo ufw enable

Check the status:

sudo ufw status

Step 4: Set Up SSH Key Authentication

For enhanced security, configure SSH key authentication, which will allow you to disable password-based logins.

  1. On your local machine, generate an SSH key pair (if you don’t have one):

    ssh-keygen -t rsa -b 4096
    
  2. Copy the public key to your VPS:

    ssh-copy-id your_username@your_vps_ip
    
  3. Log in using the SSH key to confirm it’s working:

    ssh your_username@your_vps_ip
    

Step 5: Disable Root Login and Password Authentication

Once SSH keys are working, it’s a good idea to disable root logins and password-based authentication.

Edit the SSH configuration file:

sudo nano /etc/ssh/sshd_config

Set the following options:

PermitRootLogin no
PasswordAuthentication no

Restart the SSH service:

sudo systemctl restart ssh

Step 6: Set the Time Zone

Setting the correct time zone helps ensure logs and scheduled tasks run on time.

sudo timedatectl set-timezone your_time_zone

You can list all available time zones with:

timedatectl list-timezones

Fail2Ban helps secure your VPS by banning IP addresses that show malicious signs, such as too many failed login attempts.

Install Fail2Ban:

sudo apt install fail2ban -y

Start and enable the Fail2Ban service:

sudo systemctl start fail2ban
sudo systemctl enable fail2ban

Conclusion

These basic configurations will significantly improve the security and usability of your Ubuntu VPS. From here, you can continue to configure your server for specific applications, whether it’s a web server, database, or other services.