Reseller Hosting

Offer Reseller Hosting

Get Deal

How to Add an SSH Key to Your GitHub Account

Using an SSH key with GitHub provides a secure and convenient way to connect to your repositories from the command line. Instead of entering your GitHub username and password every time you push or pull code, you can authenticate using your SSH key acting as a secure digital key unique to your machine.

This guide explains how to create an SSH key on your local device and how to upload the public portion of that key to your GitHub account. If you’ve already generated an SSH key, feel free to skip to the second section.

Create an SSH Key on Your Local Machine

First, check whether you already have an SSH key:

ssh-add -l

If this command lists an existing key, you may not need to create a new one. Otherwise, follow the steps below:

  1. Open your terminal application.
  2. Run the command below, replacing name@domain.tld with your own email address: ssh-keygen -t rsa -b 4096 -C “name@domain.tld”
  3. Press Enter to confirm the default file location.
  4. When prompted, enter a secure passphrase and press Enter again.

Next, retrieve your new public key:

cat ~/.ssh/id_rsa.pub

Copy the output—this is your public SSH key, which you’ll upload to GitHub. Your SSH key has two parts:

  • The private key should remain securely stored and never be shared.
  • The public key is safe to share with services like GitHub.

Add Your SSH Key to GitHub

Once your key is created, adding it to GitHub is straightforward:

  1. Log into your GitHub account.
  2. Click your avatar in the top right corner and select Settings.
  3. In the left-hand menu, choose SSH and GPG keys.
  4. Click New SSH key.
  5. Provide a meaningful title to help you identify the key (e.g., Domain.TLD Key).
  6. Paste your copied public key into the Key field.
  7. Click Add SSH key to complete the process.

Your machine is now linked to GitHub using SSH, allowing seamless and secure access when working with your repositories. Learn how to set up git version control on cPanel.