The Ultimate Ubuntu Server Setup Tutorial for Beginners

Introduction

Embarking on the Ubuntu Server Setup may seem overwhelming for beginners. However, with proper guidance and a grasp of the process, it transforms into an attainable task. Within this comprehensive guide, we will walk you through the process of configuring your Ubuntu server from the ground up, guaranteeing a seamless and prosperous setup.

Choosing the Right Ubuntu Version

In Ubuntu Server Setup as you embark on your setup journey, selecting the appropriate version of Ubuntu is crucial. Presently, Ubuntu 22.04 stands out as a stable and reliable choice, ideal for beginners. Additionally, you have the flexibility to choose a Virtual Private Server (VPS) provider like AWS or Digital Ocean to host your server.

Step 1 – Connecting to Your Server

To access your server, open a terminal on your local machine. Depending on your preferred authentication method, you have two options:

Using SSH Keys

If you opt for SSH keys, execute the following command:

ssh username@your_server_ip

Using a Password

If you’re using a password, you’ll be prompted to enter it after running the above command. Ensure you know your server’s public IP address and the associated credentials.

About the Root User

The root user possesses administrative privileges in a Linux environment, but it’s advisable to refrain from using it regularly due to its ability to make potentially destructive changes. Instead, it’s recommended to create a new user account with reduced privileges for everyday use.

Step 2 – Creating a New User

Before creating a new user, we need to update our server by using the below command

sudo apt update
sudo apt upgrade -y

After Ubuntu Server Setup, Once you’ve logged in as the root user, you can create a new user account for regular use. In this example, we’ll create a user named “kahnu,” but feel free to choose a username of your preference:

adduser kahnu

You’ll be asked to set a strong password for the new account and provide optional additional information. Remember that this information is not mandatory, and you can skip any field by pressing ENTER.

Step 3 – Ubuntu Server SetupGranting Administrative Privileges

While you now have a new user account with standard privileges, there may be instances when you need administrative capabilities. To avoid the inconvenience of switching between user accounts, you can assign superuser privileges to your regular user. These privileges permit your standard user to run commands with administrative authority by prefixing them with “sudo.”

In your Ubuntu Server Setup To bestow superuser privileges upon your new user, add the user to the sudo system group using the following command (substitute “kahnu” with your user’s name):

usermod -aG sudo kahnu

You can now employ the “sudo” command before commands to execute them with superuser privileges when logged in as your regular user.

Step 4 – Setting Up a Firewall.

Ubuntu 22.04 servers can leverage the UFW (Uncomplicated Firewall) to restrict connections to specific services. This facilitates basic firewall setup.

Note : For Ubuntu Server Setup we are utilizing Digital Ocean as our VPS server provider. If you’ve set up your server with AWS, GCP, or any other service provider, please refer to their documentation for this step.

First, check which applications have registered profiles with UFW:

ufw app list
#OUTPUT
Available applications:
  OpenSSH

By default, OpenSSH, the service for connecting to your server, has a profile registered with UFW. Ensure that UFW allows SSH connections to permit access:

ufw allow OpenSSH
#output
Rules updated
Rules updated (v6)

Subsequently, enable the firewall:

ufw enable

Confirm your action by typing “y” and hitting ENTER.

#OUTPUT
Command may disrupt existing ssh connections. Proceed with operation (y|n)? y
Firewall is active and enabled on system startup

To verify that SSH connections are still permitted, check the status:

ufw status
#OUTPUT
Status: active

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

Step 5 – Enabling External Access(SSH) for Your Regular User

Now that you have a regular user account for daily activities, you must ensure that you can access directly into this account using SSH. The method for configuring SSH access for Ubuntu Server Setup depends on whether your server’s root account utilizes password or SSH key authentication.

If the Root Account Uses Password Authentication

After Ubuntu Server Setup, If you logged into the root account using a password, SSH allows password authentication. To SSH into your new user account, open a new terminal session and use SSH with your username:

ssh kahnu@your_server_ip

After entering your regular user’s password, you’ll be logged in. For commands requiring administrative privileges, prepend “sudo” as follows:

sudo command_to_run

You may be prompted for your regular user’s password the first time you use “sudo” during each session and periodically thereafter.

If the Root Account Uses SSH Key Authentication

After Ubuntu Server SetupIf you logged into the root account using SSH keys, password authentication is disabled for SSH. To log in as your regular user with an SSH key, add a copy of your local public key to your new user’s “~/.ssh/authorized_keys” file.

Since your public key is already in the root account’s “~/.ssh/authorized_keys” file on the server, you can copy this file and directory structure to your new user account using your current session. Use the “rsync” command to do this. It will copy the root user’s “.ssh” directory while preserving permissions and adjusting the file owners. Ensure you replace “kahnu” with your regular user’s name:

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

Now, initiate a new terminal session on your local machine and employ SSH with your username:

ssh kahnu@your_server_ip

You should successfully connect to your server with your new user account, without needing a password. For commands requiring administrative privileges, add “sudo” before the command:

sudo command_to_run

You’ll be prompted for your regular user’s password when using “sudo” during the initial session and periodically afterward.

You can follow our tutorial on how to install node in ubuntu

By following these comprehensive steps, you can adeptly perform the Ubuntu Server Setup, ensuring it aligns with your specific needs.”

Leave a Comment