As you get your new ubuntu server ready, there are certain initial configurations that you must do. These configurations will add initial level of security and will setup a solid foundation for your web server. After Initial Ubuntu Server Configuration for Nginx, you can Configure Nginx, MariaDB, PHP 8.1 (LEMP Stack) which you can use to host your website or web application.
Initial Ubuntu Server Configuration
In this tutorial, we will perform the following steps
Step 1 – Login to your server as “root”
As its a new server, the first thing that you will have to do is login as “root” user. If you have opted for private key, you will have to first install the SSH key. If you didn’t, then you can just use putty tool, enter your server’s IP under “host name” and enter “22” under “port” and click “open”. Click on “Accept” in the dialog box appeared.
Now you will see a black window with “login as”.
- Type “root” and hit “Enter” key
- Type your root password (password that you have entered at the time of creating the server)
Hurrey! you have successfully logged in to your server. Now lets proceed further.
Step 2 – Create a new user
After creating new user, we will always login using this new user only
# adduser jack
You can replace “jack” with whatever name you like. Hit “Enter”, and this command will create a new username named jack and will ask you for a new password. Make sure to enter a strong password. Next the system will ask some questions that you can fill as per your wish.
Setp 2 – Assigning administrative privileges
Now that you have a new regular user, we will have to assign administrative privileges to the user so that the user can perform various administrative tasks just by putting “sudo” infront of the command. we will also have to add the user to the “system group” because in ubuntu, members of “system group” can run commands using “sudo” by default.
# usermod -aG sudo jack
This command will add user to “system group” and assign administrative privileges as well.
Step 3 – Setting up firewall
Ubuntu uses UFW firewall. Configuring ufw firewall will ensure that only allowed connections will be able to communicate with the server. This will add a solid layer of security for the server.
OpenSSH is the service that allows you to connect your ubuntu server remotely. Given below command will examine the installed profiles.
# ufw app list
Output
Available applications:
OpenSSH
Now the first thing that you have to do is to ensure that you can connect to your ubuntu server without any issue. So you must allow OpenSSH profile in the firewall using the command given below
# ufw allow OpenSSH
Now type the below command to enable the firewall
# ufw enable
Type “y” and hit “Enter” key
Now cross check whether you have done the right configuration
# ufw status
Output
Status: active
To Action From
-- ------ ----
OpenSSH ALLOW Anywhere
OpenSSH (v6) ALLOW Anywhere (v6)
Congratulations, you have just configured your firewall that is allowing only the OpenSSH connections and denying all the others.
With this, you have successfuly completed your ubuntu server’s initial configuration. Now you can go ahead and install the applications that you wish to.