Guides: Providing your SSH Key
Overview
GitHub uses public-key cryptography and SSH to authenticate you during git’s push and pull commands. In order for GitHub to identify you, you must provide us with your SSH public key. The rest of this page contains instructions on how to locate or create a set of SSH keys.
Mac OS X
Step 1
Check to see if you already have a public/private key pair for your user. If you do, it will be in your ~/.ssh directory.
[~]$ cd .ssh
[~/.ssh]$ ls
config id_rsa.pub
id_rsa known_hosts
Key pairs are always named like something and something.pub. The something file is your private key and must be kept secret. The something.pub file is your public key, and this is what you’ll be giving us. If you already have a key pair (in the above listing I have an id_rsa key pair) and you want to use it for GitHub, then skip to Step 3.
Step 2
If you don’t have any keys yet, then you’ll need to generate them. This can be done with the ssh-keygen program.
[~/.ssh]$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/tom/.ssh/id_rsa): <enter>
Enter passphrase (empty for no passphrase): <enter password>
Enter same passphrase again: <enter password again>
Your identification has been saved in /Users/tom/.ssh/id_rsa.
Your public key has been saved in /Users/tom/.ssh/id_rsa.pub.
The key fingerprint is:
50:43:77:c6:97:af:61:82:dc:ea:9b:6b:67:d4:1b:61 tom@volcano
You are free to name your key pair whatever you like. Just make sure you copy the correct public key in the next step. The password that you enter will be requested from you every time you push or pull from a private repo. You can use ssh-agent or the built-in keychain support in Leopard to automate password entry.
Step 3
Copy your public key to the clipboard so you can easily paste it into your web browser.
[~/.ssh]$ cat id_rsa.pub | pbcopy
The pbcopy command copies whatever is sent to it on STDIN to the clipboard, ensuring that you won’t have any extraneous newlines or other problems. Now you can simply select the appropriate text entry box in GitHub and paste in your public key!
Problems?
The steps above didn’t work for me. I found that this openssh guide helped me out. The missing parts (i think) were:
- `chmod 600
.pub’ after creation. - `ssh-add
’ in my shell.
I debugged the connection by just trying a pure ssh connection to github:
`ssh -vi ~/.ssh/id_dsa.pub git@github.com’
Linux
Step 1
Check to see if you already have a public/private key pair for your user. If you do, it will be in your ~/.ssh directory.
[~]$ cd .ssh
[~/.ssh]$ ls
config id_rsa.pub
id_rsa known_hosts
Key pairs are always named like something and something.pub. The something file is your private key and must be kept secret. The something.pub file is your public key, and this is what you’ll be giving us. If you already have a key pair (in the above listing I have an id_rsa key pair) and you want to use it for GitHub, then skip to Step 3.
Step 2
If you don’t have any keys yet, then you’ll need to generate them. This can be done with the ssh-keygen program.
[~/.ssh]$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/tom/.ssh/id_rsa): <enter>
Enter passphrase (empty for no passphrase): <enter password>
Enter same passphrase again: <enter password again>
Your identification has been saved in /home/tom/.ssh/id_rsa.
Your public key has been saved in /home/tom/.ssh/id_rsa.pub.
The key fingerprint is:
50:43:77:c6:97:af:61:82:dc:ea:9b:6b:67:d4:1b:61 tom@volcano
You are free to name your key pair whatever you like. Just make sure you copy the correct public key in the next step. The password that you enter will be requested from you every time you push or pull from a private repo. You can use ssh-agent to automate password entry.
Step 3
Copy your public key to the clipboard so you can easily paste it into your web browser.
[~/.ssh]$ cat id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA1FlHRbbxXIv/hLDTeJczlEqGNt0oFcoPEEENHThzP5ku
PDsitSSUH2MATP014G/3BzaI9pdnhf02MSEcmtmIKXrm05/dzxEmp9yOY32YHyk6/rLUGGTJuWOpGt3J
6H5LWxq9yeRUuFG/pCRH3+KxOyzasSHXfXJaC5v7wPxUdAeg9k0jwsUjnqUcYvzo5+GwCXV9dIwY3Sr/
OrL2l8SCdSWyd3PLufJXKQHlouHB0NI/+G/QjWmkB8c1PJh/VuIe36mqv82V9XXKvYNaVWwz5Sg6aY9u
p2lgDEme+AFdPPjOnkdF6OHCr7ymKg6c/B2YCbOW7QN/L4uAdVOhTNnJMQ== tom@volcano
Copy the entirety of the public key to the clipboard. It is important that there are no newlines in the key (copying from the cat output in your console should work properly. Now you can simply select the appropriate text entry box in GitHub and paste in your public key!
Microsoft Windows using msysGit
Step 1
Get the Git version of mysGit at: Git-(version).exe It’s a small download and installs just by double clicking the download. msysGit is a full featured environment for working with Git under windows.
Step 2
Run Git Bash program
Step 3
Then create a ssh key by typing:ssh-keygen -C “username@email.com” -t rsa
Then enter password twice and when prompted for the name of file for the key leave blank and press enter
Step 4
Look at the output and it will hint at where the key is stored. It’s stored in a .ssh folder somewhere. The file with the public key is “id_rsa.pub”. Use windows search if you can’t find it. Then open it with notepad and copy the text. That is the public key you give to others and hosting sites. Leave the files where they are. Running ssh-keygen sets up the keys for both Git Bash and Git GUI that all come part of msysGit. NOTE: Git GUI can not yet upload to Github unless you set up ssh to upload key for you. Best to use the Git command line.
Microsoft Windows using PuTTYgen
Step 1
If you don’t have any keys yet, then you’ll need to generate them. This can be done with the PuTTYgen tool, provided by the PuTTY project. There is also an installer available that includes all of the PuTTY tools.
Step 2
Start PuTTYgen, and press the “Generate” button. PuTTYgen will prompt you to “generate some randomness by moving the mouse over the blank area”. Once this is done, a new public key will be displayed at the top of the window.
Enter in a key passphrase and confirm it in the appropriate boxes, then save your private key to a file. You can call the file whatever you like, just remember where it’s at, because you’ll have to set it up in Pageant later.
Step 3
Highlight the public key at the top of the page, and copy it to the clipboard . Now you can simply select the appropriate text entry box in GitHub and paste in your public key!
