CARVIEW |
Generating SSH keys (OSX)
This guide will step you through the process of generating a keypair on Mac OSX and uploading it to GitHub
Generating an SSH key on OSX is a fairly straightforward process. First and foremost, open up Terminal.app. You can usually find it at /Applications/Utilities
.
Backup and remove existing keys
Unless this is your first time setting up ssh or git on your computer, you should double check that keys do not already exist. If they do you can either use the existing key(s) or remove them. In either case, you should make a backup of the keys.
$ cd ~/.ssh $ ls config id_rsa id_rsa.pub known_hosts $ cd .. $ mkdir ssh_key_backup $ cp .ssh/id_rsa* ssh_key_backup $ rm .ssh/id_rsa*
Here we have an existing keypair, id_rsa
and id_rsa.pub
, which we’ve copied into ~/ssh_key_backup
before removing. By default, ssh will use keys in ~/.ssh
that are named id_rsa
, id_dsa
or identity
.
Generating a key
If you have an existing keypair you wish to use, you can skip this step.
Now that we’re certain ssh won’t use an existing key, it’s time to generate a new keypair. Lets make an RSA keypair:
$ ssh-keygen -t rsa -C "tekkub@gmail.com" Generating public/private rsa key pair. Enter file in which to save the key (/Users/tekkub/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /Users/tekkub/.ssh/id_rsa. Your public key has been saved in /Users/tekkub/.ssh/id_rsa.pub. The key fingerprint is: 01:0f:f4:3b:ca:85:d6:17:a1:7d:f0:68:9d:f0:a2:db tekkub@gmail.com The key's randomart image is: +--[ RSA 2048]----+ | .+ + | | = o O . | | = * * | | o = + | | o S . | | o o = | | o . E | | | | | +-----------------+
At the first prompt you can just hit enter to generate the key with the default name. You should use a good passphrase with your key. See Working with SSH key passphrases for more details on why you should use a passphrase and how to avoid re-entering it every time you use your key.
Note: If you don’t use the default key names, or store your keys in a different path, you will need to run ssh-add path/to/my_key
so that ssh knows where to find your key.
Adding the key to your GitHub account
Now launch your browser and open the account page. In the “SSH Public Keys” section click “add another public key”, then paste your public key into the “key” field. If you leave the title blank the key comment (your email) will be used for the title.
Make sure you use the public key (id_rsa.pub
in our example), and do not add any newlines or whitespace inside the key. To ensure you copy the key correctly, you can copy the key directly into the clipboard from Terminal.app:
$ cat ~/id_rsa.pub | pbcopy
Testing things out
Testing if our new key works is simple:
$ ssh git@github.com Hi tekkub! You've successfully authenticated, but GitHub does not provide shell access. Connection to github.com closed.
If you do not get the “successfully authenticated” message, check out the troubleshooting guide.
-
Setup
- Installing git (OSX)
- How to install git on OSX
- Generating SSH keys
- How to generate SSH keys and add them to GitHub
- Troubleshooting SSH issues
- Solutions to common SSH issues
- Setting user name, email and GitHub token
- Configure your local git installation so that commits are linked to your GitHub account
- Installing Git HTML help
- How to install the local git HTML help files
- Working with SSH key passphrases
- SSH key passphrases, why you should use them, and how to avoid re-entering them
-
Repos
- Deleting a repo
- How to remove a repo from your GitHub account
- Moving a repo
- How to move a repo from one account to another
-
Collaborating
- Forking a project
- How to fork a project, submit changes, and pull from other repos in the fork network
-
Mac
- Installing git (OSX)
- How to install git on OSX
- Generating SSH keys (OSX)
- Setting up SSH keys on Mac OSX
- Working with SSH key passphrases
- SSH key passphrases, why you should use them, and how to avoid re-entering them
-
Windows
- Generating SSH keys (Win/msysgit)
- Setting up SSH keys with msysgit on Windows
- Working with SSH key passphrases
- SSH key passphrases, why you should use them, and how to avoid re-entering them
-
Linux
- Generating SSH keys (Linux)
- Setting up SSH keys on Linux