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.)
- Start The Terminal and go to your home folder:
- Make a directory called .ssh:
- Navigate into the .ssh directory:
- 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"
- You’ll be prompted to save the file in /Users/USERNAME/.ssh/id_rsa, where USERNAME is your Mac username. Hit enter.
- 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.
- You now have a private key (id_rsa) and a public key (id_rsa.pub). Add the private key to your Mac keychain via the Keychain Access program:
ssh-add -K ~/.ssh/id_rsa
- 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.
- Copy the public key to your clipboard:
pbcopy < ~/.ssh/id_rsa.pub
- Log into GitHub and choose the “Settings” option underneath your profile in the upper right-hand corner of your home page:
- Choose the “SSH Keys” option along the left menu:
- Click the “Add SSH key” button in the upper right-hand corner:
- Give your key a name:
- 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”: