I will be going to show you how to create a SSH key for git so that you don’t need to type your password again and again while pushing your local code.
To check existing SSH keys in your machine run the following commands in the terminal:
cd ~/.ssh/ ls -a
This will list all your keys in the ‘~/.ssh’ folder.
To create a new ssh key you need to run:
ssh-keygen -t rsa -C "firstname.lastname@example.org" Generating public/private rsa key pair. Enter file in which to save the key (/home/JacksonIsaac/.ssh/id_rsa):
Here, your email-id will be used as a label for the SSH key.
You can simply press Enter and the SSH key will be saved as ‘~/.ssh/id_rsa’. You can also select a custom filename as per your wish.
Now you need to enter your passphrase (keep empty for no passphrase)
Enter passphrase (empty for no passphrase): Enter same passphrase again:
The SSH key will be generated and you will get your key fingerprint.
Your identification has been saved in /home/jacksonisaac/.ssh/id_rsa. # Your public key has been saved in /home/jacksonisaac/.ssh/id_rsa.pub. Your key fingerprint is: 01:0f:f4:3b:ca:85:d6:17:a1:7d:f0:68:9d:f0:a2:db email@example.com
Add your ssh key to ssh-agent
Copy your public key and paste it in the SSH Key box at ‘https://github.com/settings/ssh‘
You can view your public key by using cat (which displays the contect on the terminal itself) or use gedit to open the file and you can copy-paste the key.
Note: Remember to copy the public key (file ending with .pub) and not the private key.
You can also copy the public key using terminal clipboard tools like xclip and many more.
Let the Windows be open, and feel the Freedom.
2 thoughts on “How to Create a SSH Key for Git”
Thanks for writing this tutorial – it was easy to follow.
I only have one question, though.
Does this only apply to `git remotes` that start with `ssh`?
Because I have tried with repositories starting with `http` and `https` and it keeps asking for the GitHub username and password.
Yes the SSH key applies to only the ssh:git repo
If you have cloned using http/https you can easily do
‘git set-url origin ssh:yourGitRemoteLink’
It will ask you for your passphrase once when you set it up.
Hope this helps you 🙂