DevOps
GitHub
SSH Key Setup

SSH Key Setup

SSH (Secure Shell) keys are a safe way to authenticate with GitHub without having to enter your username and Personal Access Token every time you push or pull code.

🗝️ How SSH Keys Work


Step 1: Check for Existing Keys

Open your terminal and check if you already have SSH keys generated:

ls -al ~/.ssh

Look for files like id_ed25519.pub or id_rsa.pub. If you don't see them, proceed to the next step.


Step 2: Generate a New SSH Key

We recommend using the Ed25519 algorithm for the best security and performance.

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

When prompted to "Enter a file in which to save the key," just press Enter to use the default location.


Step 3: Add Key to the SSH Agent

The SSH Agent manages your keys in memory so you don't have to re-enter your passphrase.

# Start the agent in the background
eval "$(ssh-agent -s)"
 
# Add your private key to the agent
ssh-add ~/.ssh/id_ed25519

Step 4: Add the SSH Key to GitHub

  1. Copy your public key to your clipboard:
    cat ~/.ssh/id_ed25519.pub
  2. Go to Settings on GitHub.
  3. Click SSH and GPG keys in the sidebar.
  4. Click New SSH key and paste your key. Give it a descriptive title (e.g., "Work Laptop").

Step 5: Test Your Connection

Verify that everything is set up correctly:

ssh -T git@github.com

If you see: "Hi username! You've successfully authenticated...", you are ready to go!


[!CAUTION] Protect Your Private Key Your private key (id_ed25519 WITHOUT the .pub) is your identity. If someone gets access to it, they can impersonate you on GitHub. Keep it secret, keep it safe.