Should look like this:ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDMlUr7PCEdBmCVZHG5RqI8i7GgYAzd2G/FZ987XXa63vnqxZmZogVmmXrTnBHeM6oDv7v7g495CiiiINhJbGR4o7t4agiHOM43egDv7BbiViTlfVr3y5AxLUvRwHnC3egl8ABVX1anfXXR73x7IS3YRNWkh6gXtlhImw8UKG04UoZEmWB9BLt53lk/9c3Hxz22YZarzImrpQYy1XEUZ096B9mK/Fe+/McH78ZHUpXEgOZBIDP5KdqPk5XKznpwUDJ4/SPXPEWWCCjQ8gOoTFcFMaiMnXp5o5Udsi/DFO1TS/t8BeCRymkr5tdPvzexjkjkjkjkjkjkjkjkjkjkjkjt Ubuntu@azure-server

Here’s what it looks like for me:

Cool and you’ll also notice that there’s another file in that same directory – server-key$ ls | grep server
Here’s what that looks like for me:

Now that we have our public and private keys let’s get our VM setup.

B. Create a VM in Azure that uses the public key

1. Go to the Azure Portal

2. Select New -> Search: Ubuntu Server
(I’m using 14.04 this time)

3. Make sure you’ve selected Resource Manger and click Create:

4. Now configure the basics per our ssh-keygen parameters
Name: azure-server
VM Disk Type: Up To You
User name: Ubuntu
Authentication type: SSH public key
SSH public key: Paste the results of $ cat server-key.pub
Subscription: Depends how you want to pay for the server
Resource Group: Up to you – I’m going to create a new one so I can quickly delete it.
Location: Up to you

Should look like this:

Then select OK to go to the next section.

5. Choose Virtual Machine Size
I’m going with the smallest VM for testing.
You can also view all different VM sizes to find the right one for your use case.

6. Configure optional Features
Setting the Storage account name to something you’ll remember easily is good.
And if you want to configure ports now you can select Network Security group to allow ports specific traffic.
Here’s what that looks like:
Click okay to continue to the Summary of your VM.

Here’s our summary:

Select okay to start your VM.

7. Wait for it to be ready.
Dashboard will have an icon and you’ll get a notification when its ready:

8. Once ready select on it to see the overview and the IP address.
Should look like this:

Great! We have a VM and its IP address. Lets use our Private SSH key to connect.

C. Connect to VM using SSH Keys

1. Open bash to file location you created the keys in.
Make sure they’re there:$ ls | grep server

2. Enter this command to use SSH to connect:$ ssh -i server-key Ubuntu@52.183.31.11 -v
or more generally$ ssh -i keyname username@ip.address -v
Make sure you’re using server-key and not server-key.pub
Tip: -v is the verbose option. Not necessary, but it helps to see if the key is being accepted

3. Great, now accept the certificate, and enter your memeroablePassphrase
Whole thing should look like this:

This will allow us to open up our VM to the Public Internet via a port that we’ll connect our client side application to.

You’ll notice that SSH is already included, that’s what we’re using in our terminal. You may also have other ports opened if you’ve followed some of my other posts.

We’re going to create a new Inbound Security Rule called MongoPort where we’ll set the Destination port range to 27017 (the default port for MongoDB)

You can see the configuration pane in the screenshot above identified as item 3.

Once you hit ‘Okay’ or ‘Save’ the port will be opened in a couple seconds.

You should see a notification in the top right corner once completed. Now the port is available to the open internet, but Mongo isn’t installed or configured to be listening at that port. So let’s get to it.

2. Install Mongo

Installing Mongo on Ubuntu is easy and well documented by the MongoDB group. Just enter a few commands and you’ll be up and running in no time.

Make sure you’re following along with the directions for your specific instance of Ubuntu.

To check your version of Ubuntu enter:$ lsb_release -a

Once you’ve followed the directions provided by Mongo, here are some other helpful commands to make sure everything is configured properly.

See a log of what MongoDB is doing:$ cat /var/log/mongodb/mongod.log

See all the processes running on your machine:$ ps -aux

See all the processes with mongo in the listing:$ ps -aux | grep mongo

See the status of the ports:$ netstat -ntlp

Here’s what the bottom of my log file looks like as well as a double checking of the current status of Mongo and what port its running on.

Before we access this DB from our application we need to change one setting so Mongo accepts connections from different IP addresses besides the local IP address.

3. Configure Mongo to connect to all external IPs

Before we go on, I need to make it clear that this is not a best practice, and no user data should be stored on a VM with an open port like this. But for development and practice purposes we’re going to make it easy to connect.

When I search:
Node JS Server Azure, Ubuntu, JavaScript, Mongo, Postgres, Flask, VM
I turn up with all sorts of unhelpful results.
So I dedicated a couple days to creating a couple guides for common Cloud Stacks on Azure VMs to make it as simple as possible to start deploying your code to the cloud.

This is the introduction and at the bottom of this blog post you’ll see other workflows fill in.

First up is Storage:
This will configure what we want to name the storage account for our vm. I’ve changed mine to ‘resourcegrouponestorage’, but I could have selected any of my previous storage account in the same region, in this case westus.

Second is Network:
We can configure a Virtual Network to allow our virtual machines to connect to other resource on our network by default. We can also change this later. So in this case I’m creating the default virtual network.

Again, I could have selected a previously created Virtual Network Called ‘Databases’ which is in the same region.

Third is Extensions:
We won’t add any extensions

Fourth is Monitoring:
Which we’ll disable for simplicity sake, but is a very powerful tool one you start needing to make scaling decisions.

Fifth and finally is Availability:
We won’t use an availability set, until we need to scale out our app.

Here’s what the lower portion of our settings pane looks like:

And we’ll select OK to finish with our settings. This will take us to the summary page so we can do a one more check on our machine, don’t get to anxious about making mistakes because we can always tear this one down and spin up another if we messed something up!

Hit Okay one last time!

You’ll then be taken to your dashboard where you’ll see a nice loading tile:

It’ll take ~5 minutes to spin up and then we’ll be ready to take on the world!

Once ready it’ll look like this:

Click the tile to hit the landing page for our VM:

See that public IP address?
We’ll use that to SSH into our machine.

In my case: 13.88.180.170 !

3. Check VM using SSH

Let’s SSH into our box.

Pull out your preferred SSH client. Here’s bash on Windows and Putty Side by Side:

Notice ‘Timothy’ Triple underlined?
That’s the User Name we set during basic configuration and is paired with the password that we also set in Azure.

When you connect you might have to accept the ras2key fingerprint. It’ll look like this when using putty. Or it’ll be in the terminal using bash. Type ‘yes’ or Select Yes to continue.

When working with the cloud a any remote device being able to quickly SSH into a box is important for maintaining focus.

So, I was pleased to find a way to keep putty two clicks away by placing it in the start menu.

Here are the steps I took to keep putty handy.
And an alternate way below if you’re familiar with downloading .exe’s.

1. Download putty.exeNotice save and the small black arrow next to it?
2. Save it to your download files
3. Go to downloads folderNow you can navigate to the downloads folder from the downloads bar
4. Right click and select pin to start menu
5. Then right-click -> cut putty.exe from your downloads file and move it someplace more permanent like you’re program files.
6. Go find putty in your start menu!

Alternatively you can also save putty directly to your program files.
1. Download putty.exe
2. When the download bar appears select “save as” under the black arrow next to save.Use the small black arrow in the circle to find “save as”
3. Navigate to your program files.This is the folder I have chosen for putty
4. Select save.Here is the save button. Notice the file path. You need to navigate here to find putty in the next step.
5. Open file explorer to the file you saved putty in
6. Right click on putty and select pin to start.
7. Go find putty in your start menu.

You can resize and move the putty icon to your hearts content and never go searching for your SSH client again!