Add GitHub SSH-Key
Tags: github
Published: 2021-08-12 17:03:09

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](https://github.com/signup))

> 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.
```bash
ssh-keygen -t ed25519 -C "your_email@example.com"
```

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):
```
> 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]
```

Copy our public key. You can use tools like `xclip`. You can also use `cat` command and copy the key manually.
```bash
cat /home/you/.ssh/id_rsa.pub
```

### 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zatahzirqabzj34teg1r.png)

### 3. Go to SSH and GPG keys setting
On left menu, click SSH and GPG keys.
![Go to SSH and GPG keys setting](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gh3fn881jgtbnn52cc9r.png)

### 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5mj63a41bad3hymtc2it.png)

Fill the title and key. Remember to copy the public key on your local computer. Not the private key.
![Add title and key](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fdpqawe22jdkxygiawyt.png)

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

<a href="https://www.buymeacoffee.com/thexdev"><img src="https://img.buymeacoffee.com/button-api/?text=Buy me a macbook&emoji=💻&slug=thexdev&button_colour=FFDD00&font_colour=000000&font_family=Poppins&outline_colour=000000&coffee_colour=ffffff"></a>