shanechrisbarker.co.uk

Configuring Ubuntu, Windows and SSH

Published On: Sunday 27th of January 2019 17:58:31

Having used a Mac for my entire development career (apart from a week I spent at a company that didn't let you have coffee until 10am), I decided to invest in a shiny new Windows 10 laptop.

I remember one of the challenges I faced in the brief time I did use Windows was related to SSH. I briefly recalled having to download some extra bits in order to open an SSH connection to the test server we had.

This guide should get you up and running with SSH on a Windows client, connecting to an Ubuntu 18.10 server.

Bits you'll need

For this tutorial to work, you'll need a few bits:

Download and install the two pieces of PuTTy software and we are ready to go.

Don't have a server?

If you don't have a server, I can recommend getting one through Digital Ocean. They have plans start at just $5 a month for a server which is perfect for experimenting on and playing with. If you follow this shameless affiliate link, you'll even get $100 in free credit when you sign up (I get a little something too which will help me host this site).

Click here to head over to Digital Ocean

Configuring PuTTy and PuTTyGen

Once installed, fire up PuTTy and you should be met with the configuration screen as shown. Configuring PuTTY Screen shot
Ignore the saved sessions for now. The saved sessions allows us to quickly reload a previously used connection. We'll add ours to it once we are have successfully connected to our server for the first time.

Before we can go ahead and configure PuTTy with the parameters it needs to connect to our server, we'll first need to generate a key pair and place the public key onto our server.

Fire up PuTTyGen, ensure the key type is RSA and hit generate. In the next screen, you'll be invited to randomly move your mouse around the screen in order to generate som randomness for PuTTyGen to use:

Creating a key pair

Once this is complete, you'll be shown the public part of your key. This is the part that we will be placing onto our server so make a note of it. Although it does have the option to save the public key to a file, I believe it isn't in the correct format for our server.

Go ahead and click 'Save Private key'. Ensure you save the private key in a secure location and never give it to anyone.

Placing the key onto the server

The next step that we'll need to complete is to add the key to the server. If you have console access, go ahead and log in. Run the following commands to create the required dirtories and files, along with the permissions they'll need.

cd /home/username-you-will-be-logging-in-with // change to the SSH users directory
mkdir .ssh // make our .ssh directory
vim .ssh/authorized_keys // use vim to create the file of keys we will accept

This will create and enter a new file in a text editor called Vim. Inside of this file is where you'll want to paste the public key that you generated using PuTTYgen - If you're not familar with vim, just hit 'i' (insert) then paste in the key. Once done, hit 'esc' and type 'wq'(write, quit) before hitting enter.

With that done, our key should be saved. All we need to do now is give the file and directory we just created the correct permissions:

cd ../
chmod 700 .ssh/
chmod 600 .ssh/authorized_keys

And we're all done! Time to head back to PuTTY and finish setting up the connection.

Adding the private key to PuTTY

Head back to the puTTY configuration screen and enter the following information:

  • Enter the host name or IP of the server you want to connect to into the Session -> Host Name field (as shown in the above screenshot).
  • Click the 'Data' option located within 'Connection' - add the username that you created the ssh key for on the server.
  • Click 'Connection' -> 'SSH' -> 'Auth' and locate the field with the heading "Private key file for authentification" and hit browse. Browse to the location that you saved your private key in during the puTTY Keygen process.
  • Click back to the 'Connection' section and click Save to add our settings to the saved sessions. If you don't do this, you'll have to enter the settings again each and every time you lauch the puTTY application.

We are now ready. Hit the 'Open' button and accept the following screen which mentions about adding the key. With that, you should now be connected to your server via SSH!