(gs):GitHub
- This page was last modified on February 1, 2012, at 16:00.
From (mt) Community Wiki
Contents |
Overview
This article will provide instructions on getting your server set up to work with GitHub in a usable state.
Requirements
For the purpose of this article you'll need the following,
- GitHub account
- Have SSH set up[1] on your (gs) server
Instructions
Generating an SSH Key
First thing you should do is to make sure that you have an .ssh directory.
cd ~/.ssh
If you get an error "No such file or directory" you'll have to create it
mkdir ~/.ssh
Now you can run the following
ssh-keygen -t rsa
You should see the following output
Generating public/private rsa key pair. Enter file in which to save the key (/home/123456/users/.home/.ssh/id_rsa):
/home/123456/users/.home/.ssh/
The default will suffice for our purposes so just hit enter. The next thing you'll need to do is create a secure passphrase which you will use to authenticate when running commands to GitHub. Once successfully ran you should see a similar output
The key's randomart image is: +--[ RSA 2048]----+ | .o .o++o=o. | |...o..E.o+ + | | + .o .+.= | |o . ..+ | | . S . | | . | | | | | | | +-----------------+
Adding Your Key To GitHub
Head over to GitHub and under Account Settings, and to the SSH Public Keys section.
Back on your server you now need to get your key. When you generated your key it made two sets for you. A public key and a private key; the public key is what you'll give to GitHub.
tail /home/123456/users/.home/.ssh/id_rsa.pub
Make sure that you copy it exactly as it was output. Back on GitHub click on the link to 'Add a new public key'. You can call this whatever you wish, then add your key and save.
Testing Out Your Key
Now that you have your key saved on GitHub lets test it out.
ssh -T git@github.com
You should get the following response
The authenticity of host 'github.com (207.97.227.239)' can't be established. RSA key fingerprint is (16:27:ac:a5:76:28:2d:65:3b:54:r4:58). Are you sure you want to continue connecting (yes/no)?
Type in yes to this question and you'll receive the following
Hi username! You're successfully authenticated, but GitHub does not provide shell access.
Congratulations, you've set up your key properly!
From this point forward you should be able to run all the git commands you desire to GitHub assuming you have set up your repository[2] correctly
Skip Manual Authentication
Now that you have your key and you're starting to run git commands it's starting to get annoying to have to type in your passphrase every time, isn't it? If you're on a windows machine you could use pageant, or on OSX the keyring but because this is our server we don't have access to those tools, however, Linux does have it's own variant. Lets add it!
First let's see if we have the appropriate program set up for us first.
ssh-add
If you get the following message then we'll have to set it up
"Could not open a connection to your authentication agent."
Let's set it up, we'll run the following
eval $(ssh-agent)
Everything's good to go and can run the ssh-add command again.
ssh-add /location/to/your/key
Once this is done SSH will use your key automatically and you no longer have to manually authenticate.