Introduction
When you first create a new Ubuntu server, there are a few essential configuration steps you should take to increase security and usability. These steps will create a solid foundation for any subsequent software installations and configurations.
This guide walks you through logging in as root, creating a new user with administrative privileges, setting up a basic firewall, and configuring external access for your regular user.
Prerequisites
- A fresh server running Ubuntu 22.04 LTS (or later)
- Access to the root user via SSH (typically provided by your hosting provider)
- Your server's public IP address
Step 1 — Logging In as Root
To log into your server, you'll need your server's public IP address. Connect using SSH as the root user:
ssh root@your_server_ipIf this is your first time connecting, you may see a warning about host authenticity. Type yes to accept and continue.
If you're using password authentication, enter the root password. If you've configured an SSH key, you may be prompted for your key's passphrase instead.
Step 2 — Creating a New User
Once logged in as root, you should create a new regular user account for day-to-day tasks. Running everything as root is risky because even accidental commands have full destructive power.
Create a new user (replace john with your preferred username):
adduser johnYou'll be asked to set a password and fill in some optional profile information. Enter a strong password and press ENTER to skip the rest.
Step 3 — Granting Administrative Privileges
Now give your new user sudo privileges so it can run commands with superuser access when needed:
usermod -aG sudo johnYour regular user can now run commands with administrative privileges by prefixing them with sudo.
Step 4 — Setting Up a Basic Firewall
Ubuntu servers can use UFW (Uncomplicated Firewall) to manage connections. Applications can register their profiles with UFW upon installation.
List the available application profiles:
ufw app listYou should see output that includes OpenSSH. You need to allow SSH connections so you can log back in next time:
ufw allow OpenSSHNow enable the firewall:
ufw enableType y and press ENTER to confirm. Verify the firewall is active and SSH is allowed:
ufw statusYou should see output showing that the firewall is active and OpenSSH is allowed from anywhere.
Step 5 — Enabling External Access for Your Regular User
Now that you have a regular user with sudo privileges, you need to make sure you can SSH into that account directly.
If root uses password authentication, you can simply SSH with your new username:
ssh john@your_server_ipIf root uses SSH key authentication, you need to copy the public key to your new user's account. The easiest way while still logged in as root:
rsync --archive --chown=john:john ~/.ssh /home/johnThis copies the root user's ~/.ssh directory (including the authorized_keys file) to the new user's home directory with correct ownership.
Now open a new terminal session and test logging in:
ssh john@your_server_ipOnce confirmed, you can run administrative commands by prefixing them with sudo:
sudo command_to_runYou'll be prompted for your regular user password the first time you use sudo in each session.
Conclusion
Your server now has a solid security foundation. You have a non-root user with sudo privileges, a firewall allowing only SSH traffic, and secure remote access configured. From here you can install and configure any software your server needs — just remember to open the appropriate firewall ports (e.g. sudo ufw allow 80/tcp for HTTP) as you go.
For more details on UFW, see the official guide on How to Configure a Firewall with UFW.

