DEV Community

Cover image for The minimal server setup guide.
Uddesh
Uddesh

Posted on

The minimal server setup guide.

Setting up a server could be painful especially when you are in a hurry. Also, you can't just create an instance on cloud-like AWS or GCP and put your content and serve it. A server needs to be properly set up to secure it from attacks and serve content that you want.

In this post, we will go step by step to set up the server with minimum required things or you can say the right way. So without wasting any time let's get started.

At this point, I'm assuming that you have an instance created on cloud providers like AWS, GCP, or Digital ocean.

1: SSH to your server.

$ ssh -i location/to/your/private_key username@ipv4
Enter fullscreen mode Exit fullscreen mode

This command allows you to ssh or login to your server.

2: The first thing after login into the server is update and upgrade the packages.

$ sudo apt update

$ sudo apt upgrade
Enter fullscreen mode Exit fullscreen mode

Run these commands respectively.

3: Now to secure your server you should always disable root login to do so run this command.

$ sudo adduser user_name
Enter fullscreen mode Exit fullscreen mode

Now, this command just asks for a password and all fill the required information. The command output will look like this.

Alt Text

4: After creating the user we need to add the user to sudo group and grant permission to perform superuser tasks.

$ usermod -aG sudo user_name

// This command will switch user to newly created user.
$ su user_name
Enter fullscreen mode Exit fullscreen mode

5: Now change directory to home and add your ssh key for logging in into new user.

$ cd ~

$ mkdir -p ~/.ssh

// paste your local system public key here and save.
$ sudo nano ~/.ssh/authorized_keys
Enter fullscreen mode Exit fullscreen mode

6: As we added new user we should disable root login now.

$ sudo nano /etc/ssh/sshd_config
Enter fullscreen mode Exit fullscreen mode

This will open a file, find the line PermitRootLogin, and change yes to no.

Alt Text

7: To see these changes in action restart the ssh demon.

$ sudo service sshd restart
Enter fullscreen mode Exit fullscreen mode

That's it for setting up and securing the server quickly.

Now for better security, you should configure your firewall too.

By default, the fireball is inactive you need to activate it first.

8: to see the fireball status.

$ sudo ufw status
Enter fullscreen mode Exit fullscreen mode

9: To enable fireball.

$ sudo ufw enable
Enter fullscreen mode Exit fullscreen mode

10: By default, fireball rejects all requests on all ports so you have to explicitly allow the ports you want to access.

$ sudo ufw allow ssh

$ sudo ufw allow http
Enter fullscreen mode Exit fullscreen mode

These are the common services you need to allow.

After allowing these two fireball status should look like this.

Alt Text

That's it. Now your server is ready, install 'nginx' or apache and start serving your content.

I hope you will find this useful. I'll be back with another post until then Goodbye.

Alt Text

Top comments (1)

Collapse
 
horomancer profile image
horomancer

::put on wizard hat and robes::
I ENABLE FIREBALL!