Initial Server Setup with Ubuntu 20.04
To set up your server with Ubuntu 20.4 , follow the steps:
Step 1 — Logging in as root
Log in now as the root user using the following command
Accept the warning about host authenticity if it appears.
Step 2 — Creating a New User
Once you are logged in as root, you’ll be able to add the new user account. In the future, we’ll log in with this new account instead of root.
# adduser Yourname
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 would like. This is not required and you can just hit
ENTER in any field you wish to skip.
Step 3 — Granting Administrative Privileges
Now we have a new user account with regular account privileges. However, we may sometimes need to do administrative tasks.
To avoid having to log out of our normal user and log back in as the root account, we can set up what is known as superuser or root privileges for our normal account. This will allow our normal user to run commands with administrative privileges by putting the word
sudo before the command.
To add these privileges to our new user, we need to add the user to the sudo group. By default, on Ubuntu 20.04, users who are members of the sudo group are allowed to use the
As root, run this command to add your new user to the sudo group (substitute the highlighted username with your new user):
# usermod -aG sudo Yourname
Now, when logged in as your regular user, you can type
sudo before commands to run them with superuser privileges.
Step 4 — Setting Up a Basic Firewall
Ubuntu 20.04 servers can use the UFW firewall to make sure only connections to certain services are allowed. We 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 allowing us to connect to our server now, has a profile registered with UFW.
You can see this by typing:
ufw app list
Output Available applications: OpenSSH
We need to make sure that the firewall allows SSH connections so that we can log back in next time. We can allow these connections by typing:
ufw allow OpenSSH
Afterward, we can enable the firewall by typing:
y and press
ENTER to proceed. You can see that SSH connections are still allowed by typing:
OutputStatus: active To Action From -- ------ ---- OpenSSH ALLOW Anywhere OpenSSH (v6) ALLOW Anywhere (v6)
As the firewall is currently blocking all connections except for SSH, if you install and configure additional services, you will need to adjust the firewall settings to allow traffic in.
Step 5 — Enabling External Access for Your Regular User
Now that we have a regular user for daily use, we need to make sure we can SSH into the account directly.
The process for 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 up a new terminal session and using SSH with your new username:
After entering your regular user’s password, you will be logged in. Remember, if you need to run a command with administrative privileges, type
sudo before it like this:
You will be prompted for your regular user password when using
sudo for the first time each session (and periodically afterward).
To enhance your server’s security, we strongly recommend setting up SSH keys instead of using password authentication.