Generating a SSH Key – Windows

Generating a SSH key on Windows can really depend on what tool you are using to manage your Git repositories.  For CITL, we will focus on GitHub GUI.  This tool comes with two packages, a command line or shell and a friendly user interface.  Generating a ssh key with this tool is common for many Windows based Git tools.  To get started, lets open Git Shell.

gitshell

Please note that the initial location you see (J:\Repos in the image above) may not be the same on your machine, please ignore that for now.

In here, you will want to type the command:
ssh-keygen -t rsa -C “<Your Email Address>”

firstcmd

Leave the save location as is by hitting <Enter> and leave the passphrase empty.  After doing so, your screen should look like the image above.

Now you will want to print the key to the console so you can copy and paste it into GitLab.  Run the command:
cat ~/.ssh/id_rsa.pubB
(In many cases, you may need to put the full path:
cat c:\Users\<Your Username>\.ssh\id_rsa.pub

ssh_cat

Now you will want to copy this (right click the top bar where it says Windows Powershell) and click Edit->Mark.  Start at “ssh-rsa” and drag your cursor to the end of your email address.  Then right click your mouse to copy the text. (The white highlighting will go away indicating that you have copied the key)

Now, go to http://repos.citl.mun.ca, log in, and navigate to Profile Settings->SSH Keys and paste the key into the textbox called “Key”.  Before you click Add Key, the copy method we used will add line breaks to the key.  Ensure those are removed by clicking the start of each line and hitting backspace.  Your key should look like this when done:

key_repos

The Title can be named anything, I recommend you use something like <Username>-workstation.

Once the key is successfully added, you can test it by going back to the shell window and typing:
ssh git@repos.citl.mun.ca

The response should look like the image below:

ssh_success

As you can see above, a success message with your name will pop up indicating your key is working.  If you are asked for a password, the key did not add successfully.  Return to the top and walk through these steps again.  When removing the line breaks from the key, ensure you did not accidentally delete and of the characters, just because the key added to GitLab, does not mean it is the correct one.