SSH Setup for GitHub on Linux

This guide provides step-by-step instructions to configure SSH on a Linux system and use it with GitHub.

Table of Contents

  1. Check for Existing SSH Keys
  2. Generate a New SSH Key Pair
  3. Add Your SSH Key to the SSH Agent
  4. Copy the SSH Public Key
  5. Add Your SSH Key to GitHub
  6. Test Your SSH Connection

Check for Existing SSH Keys

First, check if you already have SSH keys set up on your Linux system.

ls -al ~/.ssh

If you see id_rsa.pub or id_ecdsa.pub, you might already have an existing public key. If not, proceed to the next step to generate a new key pair.

Generate a New SSH Key Pair

To generate a new SSH key pair, use the ssh-keygen command:

ssh-keygen -t ed25519 -C "your_email@example.com"
  • -t ed25519: Specifies the key type. You can also use rsa or ecdsa.
  • -C "your_email@example.com": A comment to identify the key.

Follow the prompts. You can press Enter to accept the default file location and create an optional passphrase for added security.

Add Your SSH Key to the SSH Agent

To ensure the SSH agent is running and add your key to it:

eval "$(ssh-agent -s)"  # Starts the SSH agent if not running
ssh-add ~/.ssh/id_ed25519  # Replace with your key type if different

Copy the SSH Public Key

Before adding your SSH key to GitHub, you need to copy the public key. Use the cat command to display the contents of your public key file and copy it to your clipboard.

cat ~/.ssh/id_ed25519.pub  # Replace with your key type if different

Select and copy the entire output, ensuring you include the ssh-ed25519 (or similar), the key, and your comment (usually your email).

Add Your SSH Key to GitHub

  1. Go to GitHub SSH settings.
  2. Click "New SSH Key".
  3. Give your key a descriptive title (like "Personal Laptop" or "Work Computer").
  4. Paste the SSH public key that you copied earlier.
  5. Click "Add SSH Key".
  6. GitHub might ask for your account password to confirm the change.

Test Your SSH Connection

To ensure everything is set up correctly, test your SSH connection to GitHub:

ssh -T git@github.com

If you see a message like "You've successfully authenticated," you're all set! If you encounter any errors, double-check your steps or consult GitHub's troubleshooting documentation.


That's it! You now have SSH set up to securely connect with GitHub. You can now clone, push, and pull repositories without needing to enter your GitHub password each time.