
INTRODUCTION:
When you first create a new Ubuntu 22.04 server, you should do some important configuration:
Enhance security: By configuring user accounts, firewalls, and other settings, you’ll create a robust foundation for a secure server environment.
Improve usability: Setting your preferred time zone and installing essential tools will make working with your server more convenient.
Prepare for further customization: These initial steps lay the groundwork for efficiently installing and configuring various services and applications on your server.
Step 1 - Logging in as root:
The initial setup process for Ubuntu 22.04 server often starts with logging in as the root user. The root user account possesses the highest level of privileges on the system, granting complete control over all aspects of the server. Server’s public IP address must known to log into your server.
During the login process, you’ll be prompted to enter the root user’s password. Ensure you have a strong and unique password set for enhanced security. While the server is not currently connected, log into the root user with using below command (replace the command “your_server_ip” with your server’s public IP address):
ssh root@your_server_ipAccept if any warnings are appears about host authenticity. If you are using password authentication, you must provide a root password to log in. In SSH, key is passphrase protected, need to enter the passphrase that first time you use a key each session. Your server is logging first time with password, you need to change the root password.
The root user is the administrative user in Linux environment; it possesses the highest level of privileges on the system. Using the root account for everyday tasks creates a larger attack surface, making the server more susceptible to unauthorized access attempts.
To enhance security, let’s create a new user account with limited privileges for everyday tasks.
Step 2 – Creating a New User
Once you logged in as root, you will be able to add the new user account in future. Log into the new account instead of root. The following command creates a new user , use your preferred name instead of ‘username’
adduser usernameEnter a strong password when prompted, and confirm it by entering it again.
For security, Linux does not display your passwords as you type it. This prevents anyone watching your screen from easily capturing your password.
Step 3 – Granting Administrative Privileges
We created a new user account with regular account privileges. Although, in sometimes there is a chance to do administrative tasks, to avoid to have log out of normal user and log back in root account, we can setup superuser or root privileges for our normal account. This allows normal user to run commands with administrative privileges by using the word sudo before command.
The user of the sudo group need to be added for using these privileges to your new user by default on Ubuntu 22.04 those who are the members of sudo groups are allowed to use the sudo command. Below command is used to add new user to the sudo group.
usermod -aG sudo usernameWhen you logged in your regular user, you can type sudo before command to run them with superuser privileges.
Step 4 – Setting Up a Firewall
UFW (Uncomplicated Firewall) is a firewall configuration tool that comes with Ubuntu servers. The UFW firewall acts as a gatekeeper for your Ubuntu server ensuring only authorized connections reach your services. Unlike traditional methods, applications can register profiles with UFW during installation. These profiles provide a user-friendly way to manage access by service name instead of complex port numbers.
By utilizing UFW and its application profiles, you can maintain a secure and streamlined server environment, granting access only to the services you require.
You can check this by using:
ufw app listOpenSSH
The firewall allows SSH, which lets you log back in to the server whenever needed. We can allow this connection using:
ufw allow OpenSSH
Then, we can enable the firewall, Use:
ufw enable
Type y (yes) and press ENTER to proceed. To check if SSH connections are permitted after applying the firewall rules, use:
ufw status
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 into your server.
Safe And Secure Server Setup With Ubuntu 22.04 !

INTRODUCTION
When you first create a new Ubuntu 22.04 server, you should do some important configuration:
Enhance security: By configuring user accounts, firewalls, and other settings, you’ll create a robust foundation for a secure server environment.
Improve usability: Setting your preferred time zone and installing essential tools will make working with your server more convenient.
Prepare for further customization: These initial steps lay the groundwork for efficiently installing and configuring various services and applications on your server.
Step 1 - Logging in as root:
The initial setup process for Ubuntu 22.04 server often starts with logging in as the root user. The root user account possesses the highest level of privileges on the system, granting complete control over all aspects of the server. Server’s public IP address must known to log into your server.
During the login process, you’ll be prompted to enter the root user’s password. Ensure you have a strong and unique password set for enhanced security. While the server is not currently connected, log into the root user with using below command (replace the command “your_server_ip” with your server’s public IP address):
ssh root@your_server_ipAccept if any warnings are appears about host authenticity. If you are using password authentication, you must provide a root password to log in. In SSH, key is passphrase protected, need to enter the passphrase that first time you use a key each session. Your server is logging first time with password, you need to change the root password.
The root user is the administrative user in Linux environment; it possesses the highest level of privileges on the system. Using the root account for everyday tasks creates a larger attack surface, making the server more susceptible to unauthorized access attempts.
To enhance security, let’s create a new user account with limited privileges for everyday tasks.
Step 2 – Creating a New User:
Once time you logged in root, you can able to add the new user account in future. Log into the new account instead of root. The above command creates a new user you can give what name you like,
adduser usernameEnter a strong password when prompted, and confirm it by entering it again.
For security, Linux does not display your passwords as you type it. This prevents anyone watching your screen from easily capturing your password.
Step 3 – Granting Administrative Privileges:
We created a new user account with regular account privileges. Although, in sometimes there is a chance to do administrative tasks, to avoid to have log out of normal user and log back in root account, we can setup superuser or root privileges for our normal account. This allows normal user to run commands with administrative privileges by using the word sudo before command.
The user of the sudo group need to be added for using these privileges to your new user by default on Ubuntu 22.04 those who are the members of sudo groups are allowed to use the sudo command. Below command is used to add new user to the sudo group.
usermod -aG sudo usernameWhen you logged in your regular user, you can type sudo before command to run them with superuser privileges.
Step 4 – Setting Up a Firewall:
UFW (Uncomplicated Firewall) is a firewall configuration tool that comes with Ubuntu servers. The UFW firewall acts as a gatekeeper for your Ubuntu server ensuring only authorized connections reach your services. Unlike traditional methods, applications can register profiles with UFW during installation. These profiles provide a user-friendly way to manage access by service name instead of complex port numbers.
By utilizing UFW and its application profiles, you can maintain a secure and streamlined server environment, granting access only to the services you require.
You can see this by typing:
ufw app listOpenSSH
The firewall allows SSH, which lets you log back in to the server whenever needed. We can allow these connections by typing this command:
ufw allow OpenSSH
Then, we can enable the firewall by typing this command:
ufw enable
Type y (yes) and press ENTER to proceed. To check if SSH connections are permitted after applying the firewall rules, use:
ufw status
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 into your server.

