Why SSH Keys for Git Hub
SSH keys provide a secure connection to Git Hub without the need to enter your username and password every time you want to connect and download code from Git Hub repository.
The vast majority of users may use HTTPS URLS to clone repositories, for instance https://github.com/threenine/orion.git, . However, there is an alternate approach which makes use of SSH URLS email@example.com:threenine/StopWebCrawlers.git.
In this post I will provide instructions on how to generate SSH keys for Git Hub on OSX and Linux machines. If you're on a Linux machine you may want to check out this handy little tutorial on how to use pbcopy on ubuntu.
Generate SSH keys
To generate SSH you will need to open a Terminal Window and navigate to your SSH key directory and check for any existing keys
If you get a No such file or Directory error changing into the directory, chances are the directory doesn't exist. We will therefore need to create it.
mkdir -p $HOME/.ssh chmod 0700 $HOME/.ssh
If the folder previously existed just check to see what files existed
f you see some names similar to id_rsa, we could delete them or back them up into a separate folder.
mkdir key_backup cp id_rsa* key_backup rm id_rsa*
Now we can generate a new SSH key pair using the ssh-keygen command. We will be using your email address.
ssh-keygen -t rsa -C "firstname.lastname@example.org"
Answer the additional questions. Personally I think it is better to keep the default name of id_rsa .
Once we have completed the key generation, we need to copy the content of the id_rsa.pub to your clipboard . We will use pbcopy to do this. If you're on a Linux machine you may want to check out this handy little tutorial on how to use pbcopy on ubuntu.
pbcopy < ~/.ssh/id_rsa.pub
Adding your key to GitHub
Login into your GitHub.com account, go to your Account Settings and add the new SSH key. Assign a name, such as the name of your computer, and paste the value of your public key.
Once you've completed the above step, you can now test the SSH connection to GitHub, by executing the following command in your terminal.
ssh -T email@example.com
If you see a response similar too :
Hi your-GitHub-username! You've successfully authenticated, but GitHub does not provide shell access.
Then everything is set up.
The first time you connect to GitHub , you may recieve an Authenticity of Host .... Can't be established. Don't panic, just proceed by answering Yes and continue.