Setting up SSH Keys for GitHub using WSL and Keychain
Tags: git, github, ssh, wsl
Published: 2022-12-07 14:47:17

---
title: Setting up SSH Keys for GitHub using WSL and Keychain
published: true
date: 2022-12-06 05:00:44 UTC
tags: git, GitHub, ssh, wsl
canonical_url: https://www.thatamazingprogrammer.com/setting-up-ssh-keys-for-github-using-wsl-and-keychain
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2pgifnb4hjki9r05f5ak.jpg
---

SSH keys are a secure and convenient way to authenticate with remote servers and services. This blog post will cover how to create SSH keys using the Keychain utility and then add the keys to GitHub.

Though GitHub is mentioned, you can use this for any remote Git service such as GitLab, Bitbucket, or Gitea.

## Installing Keychain

To use Keychain, you'll need to install it on your system. On Ubuntu or other Debian-based systems, you can use the following command to install Keychain:

```
sudo apt install keychain
```

## Creating SSH Keys

After installing Keychain, you can use the ssh-keygen command to create your SSH keys. This command will prompt you for a file to save the keys and a passphrase to protect the keys.

```
ssh-keygen -t ed25519 -C "your_email@example.com"
```

When prompted, enter a file in which to save the key (you can use the default location by pressing Enter) and enter a passphrase (this is an optional security measure that adds an extra layer of protection to your SSH key).

Take a little time to think of something unique if you plan on having multiple SSH keys.

I suggest using a system like [platform]-[user]-[PC]; Mine would like github-Programazing-WorkPC.

Once your SSH key is generated, you can view it by typing the following command:

```
cat ~/.ssh/id_ed25519.pub
```

The output will be the contents of your public SSH key, which you will need to add to your GitHub account.

## Adding the Keys to Keychain

On Ubuntu or other Debian-based systems, you can run the following command to open your shell's login script:

```
nano .profile
```

Add the following to the bottom of the file:

```
eval `keychain --agents ssh --eval ~/.ssh/yourSSHKey`
```

> Tip: If you're new to nano press `ctrl + s` to save and `ctrl + x` to exit.

After saving and returning to the terminal, you'll want to exit the terminal.

When you open the terminal again, Keychain will prompt you for your password.

That's it! Keychain will act as a go-between and keep your keys added to the same `ssh-agent` every session. You'll only have to enter the passwords again when you restart your computer.

## Adding the SSH Key to GitHub

Now that you have your SSH keys with Keychain, you can add the public key to GitHub to authenticate with the service.

To do this, log in to your GitHub account and go to the "Settings" page. From there, click on the "SSH and GPG keys" tab and click the "New SSH key" button.

Enter a name for the key in the "Title" field and then paste the contents of your public key file (located at ~/.ssh/id\_ed25519.pub) into the "Key" field. Finally, click the "Add SSH key" button to add the key to your GitHub account.

## Testing your SSH Key

Once you've added the key to GitHub, type the following into your terminal:

```
ssh -T git@github.com
```

If successful, you should be greeted with the following:

> Hi UserName! You've successfully authenticated, but GitHub does not provide shell access.

If not, I'd suggest reading [GitHub's Troubleshooting Documentation]([https://docs.github.com/en/authentication/troubleshooting-ssh](https://docs.github.com/en/authentication/troubleshooting-ssh)).

## Conclusion

By using Keychain, you can securely store your SSH keys and avoid having to enter the passphrase every time you use them. This allows for rapid development as you don't have to enter your SSH key whenever you want to push a change.