AlgoMaster Logo

GitHub SSH Setup

Last Updated: January 3, 2026

5 min read

Setting up SSH for GitHub can feel daunting at first. However, mastering this process not only enhances your workflow but also significantly increases your security when interacting with repositories. SSH (Secure Shell) provides a secure channel over an unsecured network, allowing you to push and pull code without repeatedly entering your username and password.

Let's dive into the details of setting up SSH for GitHub and explore the nuances that make this process smooth and efficient.

Understanding SSH

Before we jump into the setup process, it's essential to understand what SSH is and why it matters. SSH is a protocol that allows secure remote login and other secure network services over an insecure network.

When you connect to GitHub using SSH, you authenticate your identity without sending your password over the network. Instead, SSH uses a pair of cryptographic keys: a public key (which you share with GitHub) and a private key (which you keep secure). This method not only enhances security but also simplifies your workflow.

Key Concepts

  • Public Key: This key is stored in your GitHub settings and can be shared openly. It allows GitHub to verify your identity.
  • Private Key: This key is stored on your local machine and should never be shared. It proves your identity to GitHub.

Generating SSH Keys

The first step in the SSH setup process is to generate your SSH key pair. This is done using a command-line tool that comes with Git.

Step-by-Step Key Generation

  • Open your terminal (or Git Bash on Windows).
  • Run the following command to create a new SSH key pair:
  • -t rsa: Specifies the type of key to create, in this case, RSA.
  • -b 4096: This sets the number of bits in the key. A larger key size provides better security.
  • -C "your_email@example.com": This adds a label to the key, usually your email address.
  • When prompted, press Enter to accept the default file location. This is usually ~/.ssh/id_rsa.
  • Optionally, you can secure your key with a passphrase. This adds another layer of security.

Verifying Key Generation

After key generation, you should have two files in your .ssh directory:

To verify the keys were created successfully, you can list the contents of the .ssh directory:

Adding Your SSH Key to the SSH Agent

Next, you need to ensure that the SSH agent is running. The SSH agent is a program that holds your private keys and manages your authentication.

Start the SSH Agent

Run the following command in your terminal:

This command will start the SSH agent in the background. You should see output similar to this:

Add Your SSH Key to the Agent

Now, you can add your private key to the SSH agent with the following command:

If you secured your key with a passphrase, you will be prompted to enter it.

Adding Your SSH Key to GitHub

Now that your SSH keys are set up and managed by the SSH agent, it's time to add your public key to your GitHub account.

Copy Your Public Key

You need to copy the contents of your public key to your clipboard. You can do this with the following command:

Add the Key to GitHub

  1. Go to GitHub and log in to your account.
  2. Click on your profile picture in the upper-right corner, then go to Settings.
  3. In the sidebar, click on SSH and GPG keys.
  4. Click the green New SSH key button.
  5. In the Title field, add a descriptive label for the new key. This could be the name of your computer.
  6. In the Key field, paste your public key (the contents you copied earlier).
  7. Click the green Add SSH key button.

Your public key is now associated with your GitHub account.

Testing Your SSH Connection

To ensure everything is set up correctly, you should test your SSH connection to GitHub.

Running the Test

In your terminal, run the following command:

If your setup is correct, you should see a success message like this:

If you encounter issues, double-check that your public key is correctly added to GitHub and that your SSH agent is running with the key loaded.

Common Issues and Troubleshooting

Even with a straightforward setup process, you might run into a few common issues. Here are some troubleshooting tips.

Incorrect Key Permissions

Your private key file should have strict permissions. If you receive permissions-related errors, adjust the permissions with:

SSH Agent Issues

If you encounter errors related to the SSH agent, ensure it is running. You can restart it and re-add your key:

Multiple Keys

If you have multiple SSH keys, you may need to specify which key to use by modifying the SSH config file. Create or edit the ~/.ssh/config file:

This directs SSH to use the specified key when connecting to GitHub.

Now that you understand how to set up SSH for GitHub, you're ready to explore HTTPS setup. In the next chapter, we will look at how to work with GitHub repositories using HTTPS, including the advantages and potential trade-offs of this method.