Open In App

How to Generate Public SSH or GPG Keys using Git Commands?

Last Updated : 31 Aug, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

When working with a GitHub repository, you’ll often need to identify yourself to GitHub using your username and password. An SSH key is an alternate way to identify yourself that doesn’t require you to enter your username and password every time. SSH keys come in pairs, a public key that gets shared with services like GitHub, and a private key that is stored only on your computer. If the keys match, you’re granted access. The cryptography behind SSH keys ensures that no one can reverse engineer your private key from the public one. As SSH/GPG keys are used to authenticate and establish an encrypted communication channel between a client and a remote. So there is a need of creating and adding them to your GitHub account to make it secure and easy in pushing locally etc.

Steps to Generate SSH Key

First, open your Git Bash terminal. Now, just run the following commands to get your keys. Type ssh-keygen -o and then press enter. It will ask, for some confirmations, just press Enter, y, Enter, Enter respectively.

Generate SSH Key

 

Type cat ~/.ssh/id_rsa.pub and then press enter. It will automatically generate your SSH key (it starts with “ssh-rsa”). Now copy the key and Add it as a “New SSH key” present there in the SSH and GPG keys section of your Github profile setting.

 Generate SSH Key

 

Now you’re good to go. 


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads