Here’s a step-by-step guide to creating and adding your SSH key to GitHub:

1. Generate a New SSH Key Pair on Device

First, you'll need to generate a new SSH key pair (private and public) on your Raspberry Pi.

  1. Open a terminal on your Linux Device

  2. Run the following command to generate a new SSH key pair:

    ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
    • Replace your_email@example.com with the email address associated with your GitHub account.
    • The -t rsa option specifies the key type (RSA), and -b 4096 sets the key size to 4096 bits (which is recommended for better security).
  3. When prompted to save the key, press Enter to accept the default file location:

    Enter file in which to save the key (/home/pi/.ssh/id_rsa):

    If you want to save it with a different name or location, specify it, but for most users, the default location works fine.

  4. Set a passphrase (optional, but recommended for extra security) when prompted. You can also leave it blank if you prefer.

    Enter passphrase (empty for no passphrase):

2. Add Your SSH Key to the SSH Agent

  1. First, make sure the SSH agent is running:

    eval "$(ssh-agent -s)"
  2. Add your newly created SSH key to the SSH agent:

    ssh-add ~/.ssh/id_rsa

3. Copy the Public Key to Your Clipboard

Now, you'll need to copy the public key so you can add it to GitHub.

  1. To display your public key, run the following:

    cat ~/.ssh/id_rsa.pub
  2. Copy the output (the entire key starting with ssh-rsa and ending with your email address).

4. Add the SSH Key to GitHub

  1. Go to GitHub and log in to your account.

  2. In the top-right corner of GitHub, click your profile picture, then select Settings.

  3. In the left sidebar, click SSH and GPG keys.

  4. Click the New SSH key button.

  5. Paste your public key into the "Key" field, and give it a descriptive title (e.g., "Raspberry Pi").

  6. Click Add SSH key to save it.

5. Test the Connection to GitHub

To make sure everything is working, test the SSH connection by running:

Let me know if you run into any issues!

ssh -T git@github.com

You should see a message like:

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

If that works, your SSH setup is complete and you’re ready to clone, push, or pull repositories using SSH!

Additional Tips