Setting up Node JS backend on a Ubuntu droplet on Digital Ocean pt.1

Feb. 24, 2020

Posted in:

I'm going to be setting up a fresh installation of Ubuntu along with setup for a Node JS back-end for a map based team project. In this part I will be going through the initial setup of a fresh Ubuntu 18.4 installation on a droplet.

If you see any errors/typos with this article feel free to email me at mj.harakka@gmail.com and I will fix them.

First step I setup a new project called MapFox (Our team's/application's name) on Digital Ocean admin panel and after that I created a new droplet with Ubuntu 18.04 running the show.

After the droplet has been created I ssh'd into the ip address from my terminal with the command ssh root@64.225.75.7 and succesfully connected to the server.

As a first step I need to setup and configure the server with firewall and the needed dependencies for running a Node JS server. I also need to create individual userprofiles for each of the team member's so they can also ssh into the server. With Mac it's quite easy to just do from terminal but for Windows based installation you need to use an external program such as Putty as unfortunately command line on Windows doesn't understand unix based bash. Might be other ways around this on Windows but I'm not so familiar with that. (tip for everyone with Windows: Install Linux on your laptops, duh, makes life much easier unless you're doing some development relating to the Microsoft/Windows ecosystem).

Configuring the server

Reference: https://www.digitalocean.com/community/tutorials/initial-server-setup-with-ubuntu-18-04

Creating the users and granting Admin privileges

As a first priority I'm going to be creating new user's for each individual team members if for some reason they might want to get into backend. I'm also currently logged in as root which is not advisable so I created a new user for myself with the command: adduser mikko and used a fairly strong password for the user.

After this I need to grant admin/sudo priviliges for the particular user so I entered the command usermod -aG sudo mikko. Which basically grants the admin priviliges for the account and I'm running this command with root access, which basically means I can do whatever I want, which is always great. But I don't shouldn't want to be doing anything as a root unless needed.

Setting up the firewall

Here is a picture of my terminal after running the following commands.

ufw app list - to see the list of available profiles currently registered with ufw, here we can see that we have OpenSSH which is the basic daemon used for connecting remotely to a linux server with an SSH secured connection

ufw allow OpenSSH - This basically allows the firewall to accept ssh connections

ufw enable - Turn on the ufw and because of the previous step we did, we are not going to be thrown out in the middle of the SSH session. Because I'm currently running this command while SSH'ing from my Mac, if I wouldn't had allowed OpenSSH before this, I would get thrown out in the middle of the session and would have to probably log in to my server with a password.

Screenshot 2020-02-24 at 20.27.54.png

After this I tried to ssh into my server with mikko@64.225.75.7 but I actually ran into the following error.

// TODO insert screenshot

It turns out this was because I used an SSH key authentication with root in the initial connection instead of a password and it means that password authentication is disabled for the SSH connection.

This is fixed with the following command that I input as the root user:

rsync --archive --chown=mikko:mikko ~/.ssh /home/mikko

After this I managed to sign in with my 'mikko' profile but it didn't ask for a password... might be because I already SSH'f from my computer with the SSH key. Need to test this out from another machine because it would be pretty swell to not having to setup an ssh key everytime a new user wants to get into the server.

Now when I'm logged in as a Admin user I can simply use sudo to do the same thing I did as a root, but it's much simpler to have different user accounts for everyone (including me) and not having to use root.

In part 2 I'm going to be going over Node JS backend, no idea yet how I'm going to excatly do it as I've never done in on Ubuntu so I quess there's a bunch of stuff I need to readup on.

Return to blog