Getting Started with Git

14 / 16

GitHub Project - Getting Started with Git - Creating SSH keys and adding to GitHub

What are SSH keys?

SSH keys are used to identify yourself to GitHub without using username and password every time. SSH keys come in pair, a public key which is used by services like GitHub, and a private key which is stored only on our computer.

How to generate SSH keys?

Generate your ssh key pair using ssh-keygen -t rsa -b 4096 It will ask where you want to save the key. The default location is ~/.ssh/id_rsa. Press enter to continue. After this, it will ask for the passphrase. You can give an empty password by pressing enter. You will get a confirmation showing the file location.

The private key is stored in ~/.ssh/id_rsa file and public key is stored in ~/.ssh/id_rsa.pub file. You can see the content of your public key using cat ~/.ssh/id_rsa.pub command. Copy the output.

How to add SSH keys to your GitHub account?

Login to your GitHub account. Go to GitHub Settings by clicking on your display profile and select SSH and GPG keys from the side menu. Click on Add SSH keys button. Give any name to your key and paste the copied key.

Never share your private key. The public key can be shared anywhere.

Note:

  • The .ssh folder and key files should have correct permissions. You can check permissions using ls -la command and change them using chmod command
  • The .ssh directory permissions should be 700 (drwx------)
  • The public key (.pub file) permissions should be 644 (-rw-r--r--)
  • The private key (id_rsa) permissions should be 600 (-rw-------)
INSTRUCTIONS
  • Generate your ssh key pair using ssh-keygen -t rsa -b 4096
  • Save the key in ~/.ssh/id_rsa file
  • Set the password or it can be left empty
  • Copy the content of ~/.ssh/id_rsa.pub file and add it to SSH keys in GitHub account
  • Make sure you are copying only the public key stored in ~/.ssh/id_rsa.pub
Get Hint See Answer


Note - Having trouble with the assessment engine? Follow the steps listed here

Loading comments...