Setting up an SSH key for GitHub (Windows 10)

Gowantha Charithal
4 min readDec 13, 2021

Introduction to SSH

SSH, which stands for Secure Shell, is a cryptographic network protocol. It connects an SSH client application with an SSH server over a public network such as the internet. When a client connects to a server, for the connection to be considered secure, it needs to be verified. One such way to authenticate is by exchanging cryptographic keys. After successful authentication, a secure channel is provided, and SSH allows encrypted file transfer between the client and the server. SSH also allows the ability to securely execute system commands from a remote location.

Cloning with HTTPS vs Cloning with SSH

When working with GitHub repositories, one might often need to identify himself using the GitHub username and password. Using an SSH key is an alternative way to perform this identification, without having to enter your credentials every time. When cloning a repository, you get options to clone with HTTPS or clone with SSH. If you use HTTPS, you get asked to enter your credentials. When using with a remote server, it’s best advised to use SSH instead of usernames and passwords.

To clone the TestRepo shown in the above image, you must first setup SSH keys in your GitHub Account.

Generating an SSH key

To do this, a tool called ssh-keygen is used. Open the terminal and run the following command:

ssh-keygen

You will be asked where the keys should be stored. It will suggest the .ssh folder in your user folder by default. Leave it that way and press Enter.

Next you will be asked to enter a passphrase. This is to ensure that no one who has access to your PC can read the .ssh folder and impersonate you. For now, leave it empty and just press Enter twice.

Now your key will be generated, and the key’s random art image will be displayed in the terminal. If you navigate to the location you specified earlier, you’ll see two files have been created.

id_rsa — your private key

id_rsa.pub— your public key

Do not share your private key with anyone. You can share your public key with others.

Adding your SSH key to GitHub

Open your public key using a text editor, and copy all the contents in the file.

Next, go to Settings on your GitHub profile, scroll down and go to “SSH and GPG keys”

Click on “New SSH key”.

Add a title and paste the key that you copied. Then click “Add SSH key”.

You might need to enter your password for final confirmation.

Congratulations! Your SSH key is now set up.

Cloning a GitHub repository using SSH

If you try to clone the repository now, you’ll notice that the error message from before has disappeared.

You can copy the link and use the command git clone <link>to clone the repository.

Conclusion

It’s always best advised to use SSH instead of usernames and passwords when using with a remote server. I hope this article will help you setup your GitHub SSH keys.

--

--

Gowantha Charithal
0 Followers

Undergraduate at Department of Computer Science and Engineering, University of Moratuwa