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
This command allows you to
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
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
Now, this command just asks for a password and all fill the required information. The command output will look like this.
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
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
6: As we added new user we should disable root login now.
$ sudo nano /etc/ssh/sshd_config
This will open a file, find the line
PermitRootLogin, and change
7: To see these changes in action restart the ssh demon.
$ sudo service sshd restart
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
9: To enable fireball.
$ sudo ufw enable
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
These are the common services you need to allow.
After allowing these two fireball status should look like this.
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.