Request Metrics Resource Performance Monitoring

Introducing Resource Performance Monitoring

Discover the resources that slow down your website

Episode 3: SSH Keys For Server Authentication

We create a new SSH key to use for authentication to a Linux dev server. We’re rather unhip so we do it all from Windows. In the previous video, we created a build for our new project. Now we are configuring access to the development server using SSH keys. Follow along as we create a new SSH key pair using Git Bash. We’ll use PuTTY and the new key to SSH to our Linux server from a Windows machine. Generating a new SSH key is not too difficult, but there are a few gotchas when using Windows.

We are going through this exercise because Eric and Jordan develop on Windows. Todd watches in amusement as his MacOS machine “just works”.

NOTE: There’s a step you don’t see in the video. The public key we generated was placed into the authorized_keys file on the Linux server when it was first provisioned. This is why we are able to authenticate to it at the end of the video.

Generating a SSH Key in Windows

First we need a new SSH key pair. Github’s Instructions for generating a new key are straightforward and work as long as you have Git for Windows:

  1. Open Git Bash
  2. Select Help -> Show SSH KeyGenerate a new key with this command:
> ssh-keygen -t rsa -b 4096 -C "your_key_description"
  1. Tips
    • Don’t use spaces in your key comment. Some programs don’t like it!
    • Be sure to specify a location to save the key to avoid overwriting your user’s ssh key.

Just Need a Key for Git?

There is a simpler way to do this if you just need to make Git SSH repositories work. Git for Windows provides a simple way to generate the id_rsa key for your user. This method does not let you generate arbitrary keys:

  1. Open “Git GUI” and select Help -> Show SSH Key
  2. If you see no key listed, click “Generate Key” and follow the prompts:

    Generate your user's SSH key with Git GUI in Windows

Converting a RSA key to .PPK for PuTTY

Because we’re using Windows we are not quite done. We often use PuTTY to make SSH connections but it does not read the PEM formatted keys. We must convert the ssh-rsa key to the .PPK format that PuTTY uses:

  1. Open PuTTY Key Generator (PuTTYgen) and select Conversions -> Import key
  2. Import your key and re-enter the comment and passphrase.
  3. Click “Save Private Key” and you’re done:

    Use PuTTYgen to convert ssh-rsa PEM files to .ppk files

Connecting to a Linux Server With PuTTY

PuTTY does not know about our key by default which means it will fail to authenticate to our server. We need to tell PuTTY about our key by configuring Pageant:

  1. Start Pageant and double click its tray icon: Pageant Tray Icon
  2. Click “Add Key” and select your .PPK file:

    Adding a private key to Pageant

  3. Start PuTTY and connect to your server. Any key added to Pageant will automatically be used if valid for the server.

We now have SSH access to our Linux server. Thankfully this drudgery is not done very often. Now that we have a key, we can use Ansible to provision our Linux server and deploy the build from TeamCity.