Published
- 2 min read
Create GitHub SSH keys
Follow this tutorial to avoid having to enter GitHub credentials every time you need to do Git operations on private repositories.
Generate SSH key pair
Do you already have key pairs generated?
$ cd ~/.ssh
$ ls - la
If there is a id_rsa.pub
, a key-pair already exists on the machine, so GitHub needs to be notified of its existence, so skip to the "".
Use the following command to generate a new key-pair if you are missing one.
$ ssh - keygen - o - t rsa - C "captainmiller@gmail.com"
I am not sure if you need to use the same email ID that your GitHub profile is setup with.
Select the default install directory, and leave the passphrase field blank to ignore it.
Should be greeted with something that looks like below:
Your identification has been saved in /ubuntu/.ssh / id_rsa.
Your public key has been saved in /ubuntu/.ssh / id_rsa.pub.
The key fingerprint is:
00: 2a: c7: aa: aa: aa: db: aa: h5: 3r: aa: 9a: 9d: ba: a2:bd xyz @gmail.com
The key's randomart image is:
+ --[RSA 2048]----+
| |
| |
| .B + |
| .s = . |
| .S = o |
| o.O.o |
| o.+ . |
| .o -.. |
| .-+o |
+----------------- +
Adding public key to GitHub
The generated keys are stored in the same hidden directory we looked for in .ssh :
$ cat ~/.ssh/id_rsa.pub
The output of the following command should be “ssh-rsa <public-key> captainmiller@gmail.com”.
ssh - rsa XXXXB3NzaC1yc2EAAAABIwAAAQEA879BJGYlPTLIuc9R5MYiN4yc
YiCLcdBpSdzgK9Dt0Bkdddfe3rSz5cPm4wmehdasdfasdfBJ2YHqPLuM1yx1AUxIebpwlIl9aUHOts9eVnVh4NztPy0iSU
Sv0b2ODQQasdfasdfasYcujlorscl8JjAgfWsO3W4iGEe6asdfaU35v5VbylM9ORQa6wvZMVrPECBvwItTY8cZAP3MGZiK
74eHbSLKA4PY3gM4GHI450Nie16yggEg2aTQfWA1rry9JYWEoHS9pJ8OWgqJrilwSoC5rGjgp93iu0H8T6mEHGRQe84Nk1y5lES
Ibn6P636Bl3uQ == captainmiller@gmail.com
Copy the entire output including the ssh-rsa part and the email part.
The following steps are on GitHub, so switch from the terminal to the browser ensuring that the clipboard has your generated key that you just copied.
- Log into GitHub on the browser, go to account settings.
- Select SSH keys from the left pane. Then click on Add SSH key.
- Give it a meaningful Title to be able to identify the device this key was generated on, for future reference.
- Paste the whole copied text into the Key Field and add key.
Using the generated SSH keys.
Now that we successfully generated the keys, we don’t have to enter our GitHub credentials into the terminal on every operation dealing with private repos.
Make sure to use SSH, instead of HTTPS while selecting the repository you are attempting to clone.
git clone git @github.com:savingprivate/rayan.git