Tuesday, December 26, 2017

Connecting to GitHub with SSH

In this post we will see how to connect to GitHub using SSH Keys.

Environment & Tools
  • Unix (Fedora 25)
  • Spring Tool Suite 3.9.1
1. Create a folder to save the SSH Keys (e.g. /home/bala/keys)
2. Execute the following command on this folder, enter a passphrase (e.g. MyHardPassword) when asked
ssh-keygen -t rsa -b 4096 -f ./id_rsa -C "your-email@gmail.com"

where

-t -> Name of the Algorithm (e.g. rsa, ecdsa)
-b -> Key size (e.g. 2048, 4096)
-f -> File Name where the Private key is stored (public key will be stroed in id_rsa.pub file)
On issuing "ls" command you can see two files id_rsa & id_rsa.pub

3. Now log into your GitHub account and click on "Settings"

4. Choose "SSH and GPG Keys"
5. Click on "New SSH Key"
6. Give a name such as "bala-key"
7. Copy the content of the file "id_rsa.pub", generated in Step 2, and paste it
8. Once the key is saved, it would look like this
9. Create a new Repository such as "ssh-code-checkin-test"
10. Copy the SSH repository URL
11. On the command prompt issue the following command to clone the repository, note the command includes the Private key file "id_rsa" and Repository URL
GIT_SSH_COMMAND='ssh -i id_rsa' git clone git@github.com:balatamilmani/ssh-code-checkin-test.git

12.Open STS Preferences and search "SSH", on the General Tab specify directory name where the keys are stored (i.e. /home/bala/keys). On "Private keys" field mention the private key file (i.e. id_rsa which is in the same directory)

13. Create a new Project and configure it in Spring Tool Suite
14. Right click on Project and choose "Team->Add to Index", now open GIT Perspective
15. Enter a Commit Message and check in the files, if prompted provide the Passphrase (MyHardPassword) which you provided in Step 2
16. The checked in code will be in the GitHub now
Note: The same way we can configure the SSH Keys for the BitBucket as well.

No comments:

Post a Comment