Subscribe to my newsletter for the latest updates. 👇

Initial Server Setup Guide for Ubuntu 22.04

Properly setting up your server lays the foundation for everything that follows, from software installation to configuration tweaks.

It’s a critical first step that ensures smooth operation and optimal performance.

So, let’s begin the initial server setup process for Ubuntu 22.04, ensuring we start on the right foot.


To make the most of this guide, ensure you have a server running Ubuntu.

If you don’t have one, consider getting a free VPS server to follow along.

Following along on your own server will enhance your understanding and practical experience.

Changing Root Password

Changing the password of the root user should be the first step you do after connecting to your server.

Avoid using weak passwords and consider using a password manager for generating and securely storing complex passwords.

Personally, I recommend using Bitwarden.

To change the root password, use the following command:

passwd root

The passwd command is used to change the password for any user on your server.

Adding a Non-Root User

When accessing your server for the first time, you are probably using the root user, which is not recommended due to its total control over the entire server.

It is very easy to make mistakes when running commands using root, as you can accidentally break your server.

It’s safer to use a non-root user, requiring the sudo prefix for administrative commands and a password prompt.

This slight difference in permission levels makes sure you proceed carefully, as trying to execute commands without the sudo prefix will result in error messages.

To create a new user, simply use the command:

adduser <username>

The server will ask for a password and some optional details. If you’re in a hurry, just hit the ENTER key.

Now, we need to grant this user root privileges by making them part of the sudo group:

usermod -aG sudo <username>

To check that the new user is good to go, log out with the logout command and connect back to your server with the new user.

Try running the apt update command.

It should not work directly, as you need to run the command like this: sudo apt update and then enter your password.

Now you can use the non-root user instead of root.

Updating the Server

After connecting to your server, you may encounter a message indicating that there are packages, including security patches, available for updating.

Using outdated software may exposes your server to security vulnerabilities.

Therefore, a very important step in securing and maintaining your server’s health is to update your server’s packages and download any available security patches.

Begin by updating the package list on your server with the following command:

sudo apt update

This command prompts the server to scan the server’s packages and identify those requiring updates, including security patches.

Once this is done, run the following command to update your server’s packages that need updating:

sudo apt upgrade

The server may ask for confirmation by displaying a prompt that requires a yes or no response. Make sure to type yes.

The updating process may take a while, depending on the number of updates needed.

Note: Some immediately reboot after updating, but I prefer waiting until the server setup is complete to ensure all changes apply.

Regularly updating your server is not just recommended – it’s essential.

Updates provide critical security patches, performance improvements, and software bug fixes.

Neglecting updates can leave your server vulnerable to attacks.

Read more: I wrote a detailed guide on automating security updates for a Linux server. Check it out after finishing this one.

Changing Server Hostname

Setting a meaningful hostname for your servers is like giving them a name tag — it makes them easily recognizable and more user-friendly.

This comes in handy when you want to double-check that you’re working on the right server, reducing the chances of accidentally messing with the wrong one.

But, there are two main reasons why setting a hostname is important:

  • Some programs need the hostname to work correctly. Properly configuring a server’s hostname is essential for certain network services to function as they should.
  • If a server’s hostname can’t be resolved to an IP address, it can cause communication and networking issues. This may result in timeouts, connection errors, and other unexpected behavior.

To change the hostname, use the following command:

sudo hostnamectl set-hostname <>

Typically, a hostname has two parts: the server name and the domain name.

For instance, if you’re naming your server myserver and your domain is, your hostname would be

Note: Make sure to add an A record for your hostname.

Changing Timezone

Setting the timezone for your server is important because it ensures that the server’s clock matches the correct time in your specific location.

If the server’s timezone is not set right, it can cause problems like wrong timestamps on log files, scheduling issues with tasks (cron jobs), and other issues that depend on accurate time information.

Use the following command to list the available timezones:

timedatectl list-timezones

This will show you a long list of timezones to choose from.

Once you’ve picked the right one, type the following command to set it:

sudo timedatectl set-timezone <yourtimezone>

Your server is now in sync with the correct timezone.

Changing Default Editor

You can change the default editor used by your server, such as when running the crontab or visudo commands.

It’s usually Nano, but you can switch it to Vim or any other preferred editor using the following command:

sudo update-alternatives --config editor

Enter the number corresponding to the chosen editor and press the ENTER key.

Installing Essential Software

Depending on your specific needs and the purpose of your server, there may be additional essential packages you’d want to install.

I always install these packages on my servers:

sudo apt install htop git curl wget unzip net-tools

These packages cover a range of common tasks that you may encounter while managing and using your server.

Configuring SMTP Relay

It is very important to install Postfix and configure it to use an external SMTP server for sending emails.

By doing this, your server will be able to send email notifications and alerts from packages like Unattended Upgrades, for example, in case an updating process fails.

Email notifications and alerts play a crucial role in maintaining the health of your server.

Read more: I’ve written a detailed guide on configuring Postfix to use an external SMTP relay service. Be sure to check it out!


Now, let’s give the server a little reboot to make sure everything takes effect.

Use the following command to reboot:

sudo reboot

Now, all changes should be applied.

Conclusion and Final Thoughts

Great job on setting up your Ubuntu server!

Now, it’s time to take the security of your server up a notch.

I’ve put together a comprehensive guide on server hardening, which is a collection of all security measures with links to detailed guides for each.

By following these guides one by one, your server will be thoroughly secured.

If you found value in this guide or have any questions or feedback, please don’t hesitate to share your thoughts in the comments section below.

Your input is greatly appreciated, and you can also contact me directly if you prefer.


Subscribe to my newsletter for the latest updates 👇

Leave a Reply

Your email address will not be published. Required fields are marked *