Setting Up Virtual Private Server (Article)

In this tutorial, we are going to learn all about private servers and how to configure a private server, so later we can install blockchain nodes in it. Before we start getting our hands dirty with the actual installation, let’s do a quick refresher to get a basic understanding about the virtual private server or VPS.. 

What is VPS?

VPS is a virtual private server. 

As its name suggests, it’s a : 

Virtual ✔️

Private ✔️

Server ✔️

A bit different from getting a normal setup on your computer, the VPS will allow you to have the same IP address, with a server which will be available 24/7. There are a lot of VPS options out there, like Linode and Digital ocean, to name a few.

  1. Choose a VPS provider

You can choose any VPS providers of your preference, but I recommend Linode and Digital Ocean. Let’s first understand how we use a virtual private server. To understand this, first let’s go to Digital Ocean, where you can sign up if you don’t have an account yet. I already have an account so I can just log directly. 

  1. Click “create a droplet” box

After logging into the system, by clicking the “create a droplet” box, you’re going to see   from which you can choose the kind of server you want to use. Here, you can choose whether to use a different preset server or just a simple server. I prefer using Ubuntu because I find it really practical but you can basically choose any  Linux distributions you want. 

  1. Choose a distribution mode.

LTS stands for “last table release”, an important specification here. We recommend choosing the 20.04 LTS distribution mode.

  1. Choose a subscription plan. 

You can choose the regular one which amounts to 12 a month, or you can choose the premium one, it makes no difference, so totally up to you.

  1. Set the server location, 

If we want it to be located in Frankfurt, for example, then identify “Germany” as the server location. 

  1. Setting up the SSH key

Now we need to choose the SSH key which we will use to log into our account At this point, I can create a new SSH key, log into the system and access the contents there. To perform this function, you need to go to your command line, because I use Mac, I’ll open my terminal now. 

To open and see the content of the SSH use the command:

$ cd .shh

To list all the contents of this folder type, use the command: 

$ ls -alsh 

There are 2 rsa files: id_rsa and id_rsa.pub. The id_rsa is your private key, for security concerns you must not ever share it to anyone. For today’s tutorial, we are going to use the id_rsa.pub for authentication purposes. 

To see the content of the key, I can use the following command:

$ less id_rsa .pub 

Once you are inside the file, you can see something which looks like a blob of data. I selected the blob of data from here to here, then copy and paste it to the digital ocean ssh key content. 

Now I’ll rename it  “Learning DecBC” and add this ssh key to the droplet.

This is the key that we have to access the system and thus added as a security login. Here I named it “learningdecbc” with all lowercase. Whatever name you use doesn’t make any difference. 

If you scroll down, you can see a backup option, which is optional. In this step, we are basically done with the setup. Now, we can click the “Create Droplet” button. 

Now the new server is a virtual server. It’s been deployed in one of the digital ocean hosting.

We can learn some particularities of these droplets by, for example, using the IP address that we need to use to connect and can copy the IP address. 

The droplet seems to be running. If we click here we can go to a panel where we can see the detail about the droplet which has been created.

If we go to our terminal, and press “Q” to go out from here I can try to put in the following command:

$ ssh root@IPAddress 

The root here is the user that we want to connect to the server, and the IP address here that you need to add is the one that we just created in Digital Ocean. 

After you click “enter”, you will see this question below. Respond by typing “yes” 

Okay, now I’m connecting using the ssh key that we created in the previous tutorial so there is no password to enter so I can go straight into the server

There are a few things to do when we get a new server to make it up to speed and updated.  First thing is by using the following command:

$ apt get update 

This updates the server repository list, and to check if all the software and things that are installed in the server are the latest version with  no security issues, as well as that everything is ready to be updated. So, the package list has been updated at this point.

Next, we need to upgrade the server by using the following command:

$ apt get upgrade 

We do apt-get upgrade to upgrade the server. This is a little bit of a long procedure that is also going to ask us a little bit of a question for example “Do you want to continue because this is going to use this space”  and I say yes and this is going to go through all the servers. All the repositories and do an update process.

And the update is finally completed!

Now that we are connected, we need to avoid a “broken pipe” . It’s a condition where the connection gets dropped and we need to reconnect all the time. We need to make sure that the connection remains alive until we disconnect the wheeling to edit the file.

Now to edit, open the file with command:

$ pico /etc/ssh/sshd_config

Once we open this file there are particular comments about using this text editor on the server and this is different from the one that you have on your computer. For example, if we want to search a particular phrase, we press the CTRL and W to activate the search bar. 

Now, let’s say we search for a live interval and can edit the file. 

Click CTRL O to save the output in the file and we do CTRL  X to get out of the editor. 

Now, restart the sshd by using command:

$ service sshd restart

and do a reboot so we can get freshers to work for us. 

$ reboot

My other favorite virtual service provider is Linode, let’s try to make one on Linode. Although some of the steps would be similar to the Digital Ocean, it would be good to give you more variation of what VPS provider you prefer.  

Creating SSH key in Linode

Like the previous step, sign up if you do not have an account, but as I do, I just go straight to log in. Once you are inside, let’s start the tutorial!

1.     Create a Linode by clicking the “Create” button then choose Linode

2.     Choose the distribution 

Again, like the one on the Digital Ocean, I like to use the Ubuntu 21.04 

3.     Set the server location

To make it the same I’ll be using Frankfurt Germany. 

4.     Choose the Plan

I choose the 2GB for 10 a month because it’s good enough

5.     Name the label 

You can named it anything, but here I named the same things with the one on Digital Ocean which is “LearningDecBC”

6.     Creating a password 

Unlike Digital Ocean, here you need to create a password, even if we will not use it, which is a little bit of a problem because it creates some sort of security issue. I personally like to set up a server that only uses SSH keys to log in. But there is a way to disable this password, and I’ll show you how to do it later. 

7.     Create the SSH key.

Same thing, well we need to open the terminal to copy our rsa  public key using the command: 

$ less id_rsa.pub 

And paste it to the Linode and click Add Key

The difference from the digital ocean is that we cannot choose which key to add so either add them all or nothing, but let’s add them all first and then we can remove them from the server which I’m going to show you how.  

Now, if you scroll down there’s a backup option, again that’s optional. After all is set click the “Create Linode” in the button and now that your Linode is being created.  

We wait until the daily note is going to be set up and running. And you see there is already the comment that the full command to do ssh success is ssh root with IP address. This is more convenient compared to digital ocean where the full command can’t be copied and you need to type it by hand. 

Let’s go to the terminal to test it. First let’s test the connection by using command:

$ ssh root@IPAddress

Click enter, and now you shall see a question, type “yes” then enter

At this point, it has the same procedure like the one that we did on Digital Ocean. 

First update the server by using command:

$ apt get update 

Next we need to upgrade the server by using command:

$ apt get upgrade 

So at this point, it is important that we see this other couple of important things on how to get the server not to use so many keys and at the same time to remain connected and to not allow a root user to connect via password.  

Next we gonna edit the same file which is ssh.config with command:

$ pico /etc/ssh/sshd_config

To activate the search bar we do CTRL W, and let’s search for the “live”. Now let’s find the TCP Keep Alive and we put it as “yes”

Next, let’s search for the PermitRootLogin, when you find it you can see the PermitRootLogin is yes, now we rewrite it to PermitRootLogin without-password

This means that the password access is not allowed, but it can connect using the SSH keys which is what is important. 

Press CTRL O to save CTRL X to exit and we restart the services using command:

$ service sshd restart

There’s one more to go to check the authorized keys, to do that use the command:

$ pico /root/.ssh/authorized_keys

If we open it we see that there are many keys that are authorized to access the server and they are saved in one line each. 

So I want to delete all except the last one which is the one that we created together earlier. To delete it use CTRL K.

Now, I only have one, now save it by pressing CTRL O and leave the editor by pressing CTRL X. 

Okay so those are two important settings that we need to do after updating the server. Now the server is ready to install the node of our blockchain, which I’ll explain in the next article. 

So those are two different tutorials on how to install SSH Keys in 2 different VPSs, now you will have a greater understanding of Digital Ocean, or Linode and can choose which one you prefer.  For more detail tutorial, you can also check our Video on How to setup VPS