yubikey-github

Simple SSH Key Setup for GitHub

This guide provides a basic, step-by-step tutorial for generating a standard OpenSSH key and adding it to your GitHub account for secure communication with your repositories.

Prerequisites

  1. A command-line terminal:
    • Windows: PowerShell or Git Bash.
    • macOS: Terminal.
    • Linux: Any terminal emulator.
  2. Git: Installed on your system.

Step 1: Install or Verify OpenSSH

Most modern operating systems come with OpenSSH pre-installed. Here’s how to check and install it if needed.


Step 2: Generate Your New SSH Key

This process creates a standard ed25519 public/private key pair on your computer.

  1. Open your terminal.

  2. Run the following command, replacing the email with the one you use for your GitHub account.
    ssh-keygen -t ed25519 -C "your_email@example.com"
    
  3. Follow the prompts:
    • Enter a file in which to save the key: You can press Enter to accept the default location (~/.ssh/id_ed25519).
    • Enter passphrase (empty for no passphrase): It is highly recommended to create a strong passphrase. This acts as a password for your SSH key file, adding an extra layer of security. You will need to enter it again to confirm.
  4. After this, you will have two new files in your ~/.ssh/ directory:
    • id_ed25519: Your private SSH key. Never share this file!
    • id_ed25519.pub: Your public SSH key. This is the file you will add to GitHub.

Step 3: Add Your Public SSH Key to GitHub

  1. Copy your public key to the clipboard. You can display its contents in the terminal to copy it manually.

    cat ~/.ssh/id_ed25519.pub
    

    Select and copy the entire output, which starts with ssh-ed25519 and ends with your email address.

  2. Add the key to your GitHub account:

    • Log in to GitHub and go to your Settings.
    • In the “Access” section of the sidebar, click SSH and GPG keys.
    • Click the New SSH key button.
    • Give it a descriptive Title (e.g., “My Laptop”).
    • Paste your public key into the Key field.
    • Click Add SSH key.

Step 4: Test Your SSH Connection

Finally, test that your new key is working correctly.

  1. Run the following command in your terminal:
    ssh -T git@github.com
    
  2. You may see a warning about the authenticity of the host. Type yes and press Enter.

    The authenticity of host ‘github.com (IP ADDRESS)’ can’t be established. ED25519 key fingerprint is SHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU. Are you sure you want to continue connecting (yes/no/[fingerprint])?

  3. If you set a passphrase for your key in Step 2, you will be prompted to enter it now.

  4. If successful, you will see a welcome message from GitHub:

    Hi YourUsername! You’ve successfully authenticated, but GitHub does not provide shell access.

Congratulations! Your computer is now set up to securely communicate with GitHub using SSH.