Most of you seasoned developers are use to SSH keys, this was something new to me. So this is how I went about setting up my dev enviroment to use them.

First we need to check for existing SSH keys

  1. Open Terminal
  2. Enter ls -al ~./ssh to see if existing SSH keys are present:
    $ ls -al ~/.ssh
    # Lists the files in your .ssh directory, if they exist
    
  3. Check the directory listing to see if you already have a public SSH key. By default, the filenames of the public keys are one of the following:
  • id_dsa.pub
  • id_ecdsa.pub
  • id_ed25519.pub
  • id_rsa.pub

If you don’t have an existing public and private key pair. Then we can Generate a new SSH key.

Generating a new SSH key

  1. Open Terminal

  2. Paste the text below, substituting in your GitHub email address. $ ssh-keygen -t rsa -b 4096 -C "[email protected]"

This creates a new ssh key, using the provided email as a label. > This creates a new ssh key, using the provided email as a label.

  1. When you’re prompted to “Enter a file in which to save the key,” press Enter. This accepts the default file location. Enter a file in which to save the key (/Users/you/.ssh/id_rsa): [Press enter]

  2. At the prompt, type a secure passphrase. For more information, see “Working with SSH key passphrases”.

    > Enter passphrase (empty for no passphrase): [Type a passphrase]
    > Enter same passphrase again: [Type passphrase again]
    

Now adding the SSH ket to the ssh-agent

When adding your SSH key to the agent, use the default macOS ssh-add command!!

  1. Start the ssh-agent in the background.
    $ eval "$(ssh-agent -s)"
    > Agent pid 59566
    
  2. If you’re using macOS Sierra 10.12.2 or later, you will need to modify your ~/.ssh/config file to automatically load keys into the ssh-agent and store passphrases in your keychain.
    Host *
      AddKeysToAgent yes
      UseKeychain yes
      IdentityFile ~/.ssh/id_rsa
    
  3. Add your SSH private key to the ssh-agent and store your passphrase in the keychain. If you created your key with a different name, or if you are adding an existing key that has a different name, replace id_rsa in the command with the name of your private key file.

$ ssh-add -K ~/.ssh/id_rsa

Note: The -K option is Apple’s standard version of ssh-add, which stores the passphrase in your keychain for you when you add an ssh key to the ssh-agent.

Now its time to Adding a new SSH key to your GitHub account

I have bascially ripped off the tutorial from Help GitHub but this is mainly for my reference so I can have access to quickly.

If you’re using BitBucket you can go here