Sunday, November 22, 2026
TR
Linux

Initial Server Setup with Ubuntu 22.04

Initial Server Setup with Ubuntu 22.04
Contents
  1. Step 1 — Logging in as root
  2. About root
  3. Step 2 — Creating a New User
  4. Step 3 — Granting Administrative Privileges
  5. Step 4 — Setting Up a Firewall
  6. Step 5 — Enabling External Access for Your Regular User
  7. If the Root Account Uses Password Authentication

When you first create a new Ubuntu 22.04 server, you should perform some important configuration steps as part of the initial setup. These steps will increase the security and usability of your server and will give you a solid foundation for subsequent actions.

Step 1 — Logging in as root

To log in to your server, you need to know your server's public IP address . If you have installed an SSH key for authentication, you will also need the password or private key for the root user's account . If you are not already connected to your server, log in as the root user using the command below. Replace the highlighted your_server_ippart of the command with your server's public IP address:

ssh root@your_server_ip

Accept the warning about host authenticity if it appears. If your server uses password authentication, provide your root password to log in. If you are using a password-protected SSH key, you may be prompted to enter the passphrase the first time you use the key in each session. If this is your first time logging in to the server with a password, you may also need to change the root password. Follow the instructions to change the password if you receive a prompt.

About root

The root user is the administrative user in a Linux environment who has elevated privileges. Because of the increased privileges of the root account, you are discouraged from using it regularly. The root account can make very destructive changes, even by accident.

The next step is to create a new user account with reduced privileges for everyday use. Later, we will show you how to temporarily gain elevated privileges for the times you need them.

Step 2 — Creating a New User

Once you are logged in as root , you will be able to add the new user account. In the future, we will log in with this new account instead of root .

This example creates a new user named sammy , but you should replace it with a username you like:

adduser kerim

You will be asked a few questions, starting with the account password.

Enter a strong password and, optionally, fill in any of the additional information if you wish. This information is not required, and you can press ENTERon any field you want to skip.

Step 3 — Granting Administrative Privileges

Now you have a new user account with regular account privileges. However, you will sometimes need to perform administrative tasks as the root user.

To avoid logging out of your normal user and logging back in as the root account, you can set up what is known as superuser or root privileges for your user's normal account . These privileges allow your normal user to run commands with administrative privileges by putting the word sudobefore each command.

To add these privileges to your new user, you need to add the user to the sudo system group. On Ubuntu 22.04, by default, users who are members of the sudo group are allowed to use the sudo command.

As root , run this command to add your new user to the sudo group (replace the highlighted kerim username with your new user):

usermod -aG sudo kerim

Now, when you are logged in as your normal user, you can type sudobefore commands to run them with superuser privileges.

Step 4 — Setting Up a Firewall

Ubuntu 22.04 servers can use the UFW firewall to ensure that only connections to certain services are allowed. You can set up a basic firewall using this application.

Applications can register their profiles with UFW upon installation. These profiles allow UFW to manage these applications by name. OpenSSH, the service that allows you to connect to your server, has a profile registered with UFW.

You can view the list of installed UFW profiles by typing:

ufw app list
OutputAvailable applications:
  OpenSSH

You need to make sure that the firewall allows SSH connections so that you can log in to your server next time. Allow these connections by typing:

ufw allow OpenSSH

Now enable the firewall by typing:

ufw enable

Type yand press ENTERto proceed. You can see that SSH connections are still allowed by typing:

ufw status
OutputStatus: active

To                         Action      From
--                         ------      ----
OpenSSH                    ALLOW       Anywhere
OpenSSH (v6)               ALLOW       Anywhere (v6)

The firewall is currently blocking all connections except SSH . If you install and configure additional services, you will need to adjust the firewall settings to allow new traffic to your server.

Step 5 — Enabling External Access for Your Regular User

Now that you have a regular user for everyday use, you need to make sure you can SSH directly into the account.

Note: Until you verify that you can log in and use sudo with your new user, we recommend staying logged in as root . That way, if you have trouble connecting, you can troubleshoot as root and make the necessary changes . Configuring SSH access for your new user depends on whether your server's root account uses a password or SSH keys for authentication.

If the Root Account Uses Password Authentication

If you logged in to your root account using a password , then password authentication is enabled for SSH. You can SSH to your new user account by opening a new terminal session and using SSH with your new username:

ssh kerim@your_server_ip

After entering your regular user password, you will be logged in. Remember, if you need to run a command with administrative privileges, type sudobefore it like this:

sudo command_to_run

You will be prompted for your regular user password the first time you use sudoin each session (and periodically thereafter).

To increase your server's security, I strongly recommend setting up SSH keys instead of using password authentication. If the Root Account Uses SSH Key Authentication

If you logged in to your root account using SSH keys , then password authentication is disabled for SSH. To log in as your regular user with an SSH key, you must add a copy of your local public key to the new user's ~/.ssh/authorized_keysfile .

Since your public key is already in the root account's ~/.ssh/authorized_keysfile on the server, you can copy this file and directory structure to your new user account using your current session.

The simplest way to copy files with the correct ownership and permissions is the rsynccommand. This command copies the root user's .sshdirectory, preserves permissions and changes file owners in a single command. Make sure to change the highlighted portions of the command below to match your regular username:

Note: The rsynccommand treats sources and destinations that end with a trailing slash differently from those without one. When using rsyncbelow, make sure that the source directory ( ~/.ssh) does not include a trailing slash (check that you are not using ~/.ssh/).

If you accidentally add a trailing slash to the command, rsyncwill copy the contents of the root account's ~/.sshdirectory into the sudouser's home directory instead of copying the entire ~/.sshdirectory structure. The files will be in the wrong place, and SSH will not be able to find and use them.

rsync --archive --chown=kerim:kerim ~/.ssh /home/kerim

Now open a new terminal session on your local machine and use SSH with your new username:

ssh kerim@your_server_ip

You should be able to connect to your server with the new user account without using a password. If you need to run a command with administrative privileges, type sudobefore the command:

sudo command_to_run

You will be prompted for your regular user password the first time you use sudoin each session (and periodically thereafter).

Kerim Koç

Systems and infrastructure engineer. I write about Linux, open source, high availability and security.