Using Git with SSH is now the go-to way of committing and pushing changes to a remote repository using version control. With many version control services like GitHub pulling support for HTTPS token-based authentication, it is imperative to switch to a more secure and convenient way of managing your repositories.
In this tutorial, we will have a look at creating a new SSH key and adding it to your GitHub account to manage your repositories remotely from your Linux system.
Creating an SSH Key
Open up a terminal window.
At the terminal prompt, type
ssh-keygen -t ed25519 -C "<YOUR-EMAIL>"
and press enter all the way through. An SSH private-public key pair will be generated by default at
$(HOME)/.ssh/id_ed2519[.pub]
.Note: If
ssh-keygen
is not found on your system, please install theopenssh
or equivalent package.
Adding Your SSH Key to GitHub
Open up a browser window and go to GitHub.
Login with your GitHub credentials and go to Settings, then under the Access field, click on SSH and GPG keys.
Click on
New SSH key
at the top right of your screen.Give a title to your new SSH key, and ensure that the type is
Authentication key
.In a terminal window, issue the following command.
cat ~/.ssh/id_ed25519.pub
This will print out the public key that you just generated.
Note: Please do not expose your private key online.
Now, copy and paste the entire public key without extraneous characters to the Key field.
Click on Add SSH Key and follow the on-screen prompts to enable Sudo mode.
Your SSH key should be added and visible in SSH and GPG keys.
Next Steps
Note: Skip this section if you have already set up git
to recognize who you are.
Now that you have added your SSH key to your GitHub account, you have to set up
git
to recognize that you are committing.At a terminal window, type the following commands.
git config --global user.name "<YOUR-NAME>" git config --global user.email "<YOUR-EMAIL>"
You can now commit and push changes to your remote repositories on GitHub!