SSH is an acronym of the secure shell. It is a cryptographic network protocol for operating network services securely over an unsecured network.
By using SSH you can connect to GitHub without providing your username or password at each visit like when you push something on it.
Before we move towards generating an SSH key, I suggest you check if your system has any existing SSH keys or not. For checking SSH use the command mentioned below:
ls -al ~/.ssh
If your System already has SSH then it will display one of the following file:
Steps for generating SSH key:
If your system doesn’t have SSH then you should generate it first by using following steps:
Step-1: Open your terminal and use the below command. This command creates a new ssh key, using the provided email as a label.
ssh-keygen -t rsa -b 4096 -C "email@example.com"
Step-2: After completion of step-1 it will provide a prompt to “Enter a file in which to save the key,”. If you will press Enter, this accepts the default file location.
Enter a file in which to save the key (/home/you/.ssh/id_rsa): [Press enter]
Enter passphrase (empty for no passphrase): [Type a passphrase]
Enter same passphrase again: [Type passphrase again]
Tip: A passphrase is a sequence of words or other text used to control access to a computer system, program or data. It is similar to a password and by using the below command you can see the agent and their pid.
eval "$(ssh-agent -s)"
Step-3: Now add your SSH key to the ssh-agent using the command below :
If you created your key with a different name, or if you are adding an existing key that has a different name, replace id_rsa in the command with the name of your private key file.
Step-4: Add SSH key to your Github account. For that, you should copy the SSH key by using the command :
xclip -sel clip < ~/.ssh/id_rsa.pub
xclip isn’t working, you can locate the hidden
.ssh folder, open the file in your favorite text editor, and copy it to the clipboard.
Set SSH key on your Github account:
Now set SSH key on Github by using the following steps :
- Go to your Github account. In the upper-right corner of any page, click your profile photo, then click Settings.
- In the user settings sidebar, click SSH and GPG keys.
- Click New SSH key or Add SSH key.
- Fill the appropriate title and paste the key.
- Click Add SSH key.
- If prompted, confirm your GitHub password.
For any further queries visit GitHub Help