Tag Archives: ssh

Add Existing SSH Key To OSX

26 May 2016

Here are the steps to setup your Mac to work with your Git repo with the same key that you’ve been using on your other development machines.

Copy your id_rsa file into your “.ssh” folder which is a child of your home folder. This folder is hidden but can be easily revealed via this terminal command:

$ open ~/.ssh

Now that your .ssh folder is open in the finder you can easily drag/drop/copy your pre-existing id_rsa file into it.

Next, check to see if the SSH agent is running:

$ ps -e | grep ssh-agent
20207 ?? 0:00.53 /usr/bin/ssh-agent -l // its running

If it is not running:

$ ssh-agent /bin/bash

Check to see what identities have been loaded:

$ ssh-add -l

Now load your identity with this command:

$ ssh-add ~/.ssh/id_rsa

Finally, check again for the list of identities – there should be one more than before (or just one if there weren’t any previously).

$ ssh-add -l
2048 SHA256:41ZyLeEcsdfwefsdfLegsdftQdm0Ew /Users/my_mac/.ssh/id_rsa (RSA)

Generate an SSH Key Pair within Git Bash

28 Jan 2016

If you want to be able to interact with your Git account without using passwords then you need to create an SSH key pair. You will then share the public key with GitHub to indicate to your repo that your computer is trusted. The first thing to do is to create the keys.

There are a couple of ways to do this on Windows, the easiest IMO is to use Git Bash.

Launch Git Bash and then enter the following command:

$ ssh-keygen –t rsa –b 4096 –C ‘your-email@somewhere.com’

You will be prompted for the file name and location but the default will be shown to you, illustrated via the following example.

$ ssh-keygen -t rsa -b 4096 -C ‘test@test.com’
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/Rick/.ssh/id_rsa):

Hit “Enter” to accept the default.

Next you will be asked for a password. You probably don’t want a password so that you can push to your Git repo without being asked to provide one. In that case, just hit “enter” and move on.

Below is an example showing the password step:

$ ssh-keygen -t rsa -b 4096 -C ‘test@test.com’
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/Rick/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):

Next you will be asked to confirm the password – once you’ve confirmed it you will see a message indicating that both the private and public key were created:

Your identification has been saved in /c/Users/Rick/.ssh/id_rsa.
Your public key has been saved in /c/Users/Rick/.ssh/id_rsa.pub.
The key fingerprint is:
a1:51:c2:b0:f2:9h:4c:1c:eb:a6:71:01:30:b3:db:82 test@test.com

Two key files have been created. Next you probably need to copy the public key to your clipboard. Enter the following command to view your Public Key:

$ cat ~/.ssh/id_rsa.pub.

Your key will appear within the Git Bash console – copy the key text starting with “ssh-rsa” and ending with your entire email address.

In Windows you won’t be able to simply highlight the text itself at first. Hit the “CTRL + a” key combination to select everything. This enables the ability to do a normal “click drag” text selection. Select your Public Key and hit “CTRL + c” to copy it.

From here…. you likely want to use it with your GitHub account.

Or, if you are using GitLab then follow these steps:

  1. Log into GitLab and navigate to the project.
  2. In the upper right-hand corner select the options icons (cog)
  3. Click the “SSH Keys” button in the left column
  4. Click the green “Add SSH Key” button
  5. Enter a Title
  6. Paste the public key into the key textarea
  7. Click “Add key”

If you need to see all of your public keys you can do the following:

$ ls ~/.ssh/*.pub