How to Set Up SSH for GitHub

·

2 min read

Secure Shell Protocol (SSH) is a method for secure remote login from one computer to another. It provides several alternative options for strong authentication, and it protects the communications security and integrity with strong encryption. Here’s a step-by-step guide on how to set up SSH for GitHub1.

Step 1: Check for Existing SSH Keys

Before you generate a new SSH key, you should check for existing ones. If you already have an SSH key, you can use that one. If not, you’ll need to generate a new one1.

ls -al ~/.ssh
# Lists the files in your .ssh directory, if they exist

The filename for supported public keys are

If any one of the supported file is present then use it, Else generate a new SSH key

Step 2: Generate a New SSH Key

If you don’t have an existing SSH key, you’ll need to generate a new one. To do this, open Terminal (or Git Bash on Windows), and enter the following command, replacing your_email@example.com with your GitHub email address2:

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

If you are using a legacy system that doesn’t support the Ed25519 algorithm, use:

ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

This creates a new SSH key, using the provided email as a label.

Step 3: Add Your SSH Key to Your GitHub Account

Once you’ve added your SSH key to the ssh-agent, you need to add the key to your GitHub account. To do this, copy your SSH key to your clipboard, log in to GitHub, navigate to your account settings, click on the SSH and GPG link, and then click 'Add Key.

Step 4: Test Your SSH Connection

Finally, you should test your SSH connection. If everything is set up correctly, you should be able to connect to GitHub via SSH.

And that’s it! You’ve successfully set up SSH for GitHub. This will provide a more secure channel for pushing and pulling your repositories.

Note: Always remember to keep your private key secure. Never share it with anyone.

Happy coding!

Did you find this article valuable?

Support Adithyan A by becoming a sponsor. Any amount is appreciated!