Generating an SSH Key for Mac OS X with GitHub/BitBucket

This tutorial is aimed at users who want to create a new SSH key on Mac OS X and configure it for use with GitHub. (Configuring for BitBucket is exactly the same.)

  1. Start The Terminal and go to your home folder:
  2. Make a directory called .ssh:
    mkdir .ssh
  3. Navigate into the .ssh directory:
    cd .ssh
  4. Generate a new SSH key, replacing YOUR_EMAIL_HERE@YOUR_DOMAIN with your own email:
    ssh-keygen -t rsa -C "YOUR_EMAIL_HERE@YOUR_DOMAIN"
  5. You’ll be prompted to save the file in /Users/USERNAME/.ssh/id_rsa, where USERNAME is your Mac username. Hit enter.
  6. You’ll now be asked to enter a passphrase twice. A passphrase is a string of text that is something longer than a simple password. If you hit enter, no passphrase will be associated with the key. This is not advisable.
  7. You now have a private key (id_rsa) and a public key ( Add the private key to your Mac keychain via the Keychain Access program:
    ssh-add -K ~/.ssh/id_rsa
  8. With your private key now setup on your local computer, the public key must be setup with the remote host, which can be GitHub, Bitbucket, etc. I’ll use GitHub for this example.
  9. Copy the public key to your clipboard:
    pbcopy < ~/.ssh/
  10. Log into GitHub and choose the “Settings” option underneath your profile in the upper right-hand corner of your home page:1
  11. Choose the “SSH Keys” option along the left menu:
  12. Click the “Add SSH key” button in the upper right-hand corner:
  13. Give your key a name:
  14. Assuming you haven’t added anything to your clipboard since step 9, paste the contents of your clipboard under the “Key” area, then hit “Add key”:

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.