Setting up a Virtual Private Server
Hello guys! Welcome to my first blog post.
Today, we will learn how to start up a basic VPS on a selected cloud provider.
To get started, you need a Cloud Provider. In this tutorial, I picked Digital Ocean, as their pricing seemed worthy for me. I picked myself a Droplet to host my applications.
Before getting started, I recommend you learn about these prerequisites to not get confused, or you can learn as you go. If you don’t know what a certain command does, just search it up.
Prerequisites
- Fair understanding on how SSH works
- Fair knowledge of basic linux commands
- Fair understanding of private and public key encryption
Signing up
Most cloud providers will require you to enter your credit card info when you sign up. However, many cloud providers such as AWS will offer you a free tier to get started, so you won’t have to pay anything to get started.
Digital Ocean works the same. If you want to get 100$ credit for 2 months, go ahead and use my referral link.
For me, I picked the smallest Droplet which is at 4$. I kept everything the same as in the default configuration without changing anything to make it simple.
SSH Key generation
The most common method to login to a remote server is to use SSH. SSH stands for Secured Shell and is a network protocol that allows you to securely connect to a remote shell. However, before you can access the remote server, you have to authenticate yourself and there are two ways to do this,
- Password Authentication
- SSH Key Authentication
While you can simply use a password to access the remote server, the best and most secure method to access the server via your computer’s terminal is to use an SSH key. So I highly recommend you to generate a key pair on your computer and store the public key on the server. To generate a key, simply open up your terminal and type
ssh-keygen
Which will give you something like,
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/haritha/.ssh/id_rsa): /Users/haritha/.ssh/test
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/haritha/.ssh/test
Your public key has been saved in /Users/haritha/.ssh/test.pub
The key fingerprint is:
SHA256:FSurDbI7A7sRdvzQw4ef5qnXtgM5HThVXMx674fStEk haritha@Harithas-MacBook-Pro.local
The key's randomart image is:
+---[RSA 3072]----+
| .o.+. |
| .o. o |
| .oo . |
| . o .o+. . . |
| o = * S+ . . . |
| ..o = B+.. E .|
| .o. o =+ + = |
| ..o. o..+ . = o|
| ...o.oo..o . .|
+----[SHA256]-----+
Here, I created a key named “test” but when you create one, please make sure to include the full path as well as to give it a meaningful name. Furthermore, I don’t think a passphrase is necessary as long as you are the only one accessing this computer on this user account.
Then you can simply ‘cat’ your test.pub, copy and paste the public key to your server configuration page.
cat /Users/haritha/.ssh/test.pub
Then you can simply click “Create Droplet”.
The process is more or less the same across all cloud providers. Besides, for this step, the cloud providers themselves provides tons of documentation for you to skim through and understand.
Logging in to the server
Once you are done with generating the key, you can simply log in to the server using
ssh -i /Users/haritha/.ssh/digital_ocean root@SERVER_IP
If you see something like below, congratulations you are in!
root@HasathcharuDroplet:~#
Using an SSH Client
To make your log in process easier than this, I recommend you use an SSH client such as Termius. It’s completely free to use for one device and I have been using it for a long time. Trust me, keeping in mind all those your server IPs can sometimes be a headache. Termius is pretty easy and you just have to follow the onscreen instructions to set up a connection. After you set up the connection, it gives you one click access to your server.
Just click on new host to add a new host.
Then a sidebar in the right in appear like shown in the picture. There, put the public IP address of your Droplet, put an appropriate label, and configure the username to be ‘root’. Finally for the password field, click on ‘Keys’ to add a private key.
This key is the one we generated in the previous step. So to get the private key, open up a terminal / CMD and type
cat /Users/haritha/.ssh/test
Here, give the key an appropriate name, and paste the private key output by the ‘cat’ command.
After that, you are done!
Then you can click on the host to log in. If all goes well, you should be able to log in to the system.
Wrapping Up
So guys that is it for today and thank you very much for making it till the end. Happy hosting!