Adding SSH Keys for a GitHub Repository
4 minute read
This tutorial teaches how to configure an SSH Key on GitHub so that you can clone, commit, pull, and push to repositories (repos).
Contents
Keywords: ssh
Windows
Please ensure that you have Git (Git Bash) and a repository on GitHub. This tutorial was created with the REU program in mind, where the students are provided with a GitHub repository. If you are not in REU, then you can create a new repository on GitHub and clone that instead.
-
Open Git Bash by pressing the Windows key, typing
git bash
, and pressing Enter. -
Then, go on GitHub, click on your profile icon in the top right, click
Settings
, and clickSSH and GPG keys
on the left hand side. Confirm that there are no SSH keys associated with your account. If there are keys, then perhaps you have made some already. This tutorial focuses on creating a new one. -
Go back to Git Bash and type
ssh-keygen
. PressEnter
. PressEnter
again when it asks you the file in which to save the key (it should sayEnter file in which to save the key (/c/Users/USERNAME/.ssh/id_rsa):
.- If you have already created a key here, it will ask you if you would like to overwrite the file. Type
y
and pressEnter
.
- If you have already created a key here, it will ask you if you would like to overwrite the file. Type
-
Enter a password that you will remember for your SSH key. It will not appear as you type it, so make sure you get it right the first time. Press
Enter
after typing the password that you come up with. -
After seeing the randomart image associated with your SSH, you should be able to type a new command. Type
cat ~/.ssh/id_rsa.pub
and pressEnter
. Your key will appear— remember that this should not be shared with others. The key begins withssh-rsa
and it may end with your username. Copy this entire key by clicking and dragging over it, right-clicking, and clickingCopy
. -
Return to your web browser which is on the GitHub SSH key settings page. Click the green button that reads
New SSH Key
and type a Title for this key. You should name it something memorable and distinct; for example, if you just generated the key on your desktop computer, a suitable name isDesktop
. If generated on your laptop, name itLaptop
, or if you have numerous laptops, differentiate them with distinct names, and so on.- If you only have one computer and you have preexisting keys on this page, maybe some which you do not remember the password to or have fallen out of use, consider deleting them (as long as you are sure this will not break anything).
-
Paste the key into the key box. You should have copied it from Git Bash in Step #5. Then, click the green button that reads
Add SSH key
. Congratulations— you have successfully configured your SSH key. Now we will try cloning your REU repository. -
Navigate to your repository. It should be in the cybertraining-dsc directory with a name format of
xxxx-reu-xxx
. Once you are on that page, click the green button that readsCode
with a download symbol. Click theSSH
option and click on the clipboard next to the link so that you copy it. It should sayCopied!
after you click on it. -
Decide where you want your repository folder to be stored. This tutorial will clone the repo into the Documents folder. Go back to Git Bash and type
cd ~/Documents
and pressEnter
. It is a good idea to create a folder titledreu
for organization. Typemkdir reu
and pressEnter
. Typecd reu
and pressEnter
. Finally, typegit clone
, and after you put a space after clone, paste the copied link from GitHub. For example, your command should look similar to this:git clone git@github.com:cybertraining-dsc/su21-reu-361.git
Then, pressEnter
.- The shortcut
Ctrl + V
does not work in Git Bash for pasting. Instead, you can pressShift + Insert
to paste.
- The shortcut
-
Type in your password for your SSH key and press
Enter
. The repo should clone with no issue. You can now typecode .
and pressEnter
to open VSCode in this directory. ClickYes, I trust the authors
if prompted in VSCode. If you use PyCharm instead of VSCode, you can open it from Windows search; inside of PyCharm, clickFile
,Open...
and then navigate toC:
,Users
, your username,Documents
, and then click onreu
so it is highlighted in blue and then clickOK
. If PyCharm asks, you can choose to open it inThis Window
or aNew Window
.