DEV Community

Cover image for Add GitHub SSH-Key
M. Akbar Nugroho
M. Akbar Nugroho

Posted on

Add GitHub SSH-Key

GitHub is my favorite cloud repository and I've used it for a long time. It allows use to collaborate with other developers and also integrates our project with awesome tools like Travis CI, Heroku, etc to make our project easy to manage and deploy.

To connect with GitHub and doing some actions like push and pull, we have two options. Via HTTPS and SSH.

HTTPS using HTTP protocol to transfer changes to GitHub and requires us to input our username and password every time we do those actions.

While SSH using SSH protocol to transfer changes to GitHub and requires us to input our passphrase (if your provide it) and it more secure.

This article will guide you to add SSH-Key on your GitHub account. Let's try it out!

Requirements

  • SSH agent (installed on your computer)
  • GitHub account (sign-up here)

NOTE
In this article I use Ubuntu 20.04 and I will not cover about how to install SSH agent if you are using Windows. You can search it on google and back here again.

If you are using Linux or Mac OS, then you're all set because they have SSH installed.

Steps

1. Generate SSH-Key

Open your terminal and type command below.

ssh-keygen -t ed25519 -C "your_email@example.com"
Enter fullscreen mode Exit fullscreen mode

You will asked where you want to put your key. If you not sure, just leave it and enter.

Enter file in which to save the key (/home/you/.ssh/id_rsa):
Enter fullscreen mode Exit fullscreen mode

NOTE:
If you already have any SSH-Key with same name, it will override the old SSH-Key.

After that, you will asked about passphrase. Passphrase is like password. It will prompt you to input your passphrase whenever you want to connect with another host.

Enter passphrase (empty for no passphrase): [Type a passphrase]
Enter same passphrase again: [Type passphrase again]
Enter fullscreen mode Exit fullscreen mode

Copy our public key. You can use tools like xclip. You can also use cat command and copy the key manually.

cat /home/you/.ssh/id_rsa.pub
Enter fullscreen mode Exit fullscreen mode

2. Login to GitHub and go to settings

Login to your GitHub account. You will see your profile photo at the right top corner. Click it and go to settings.
Go to settings

3. Go to SSH and GPG keys setting

On left menu, click SSH and GPG keys.
Go to SSH and GPG keys setting

4. Add new SSH-Key

On this page you will see all of your SSH-Keys. To add new one, click the New SSH key button.
Add new ssh key

Fill the title and key. Remember to copy the public key on your local computer. Not the private key.
Add title and key

Save the key and you're ready to push your changes to GitHub using SSH connection. Congrats! 🥳

Top comments (0)