SSH keys and GitHub

Generate an SSH key and add it to GitHub

Generate an SSH key, add it to your GitHub account and test it, so you can push and pull without typing a password.

Fill these in once
  1. Create the key
    Terminal
    ssh-keygen -t ed25519 -C "you@example.com"

    Press Enter to accept the default file. Add a passphrase if you like.

  2. Tell your Mac to remember it
    Terminal
    cat >> ~/.ssh/config <<'EOF'
    Host github.com
      AddKeysToAgent yes
      UseKeychain yes
      IdentityFile ~/.ssh/id_ed25519
    EOF
    ssh-add --apple-use-keychain ~/.ssh/id_ed25519
  3. Copy the public key
    Terminal
    pbcopy < ~/.ssh/id_ed25519.pub
  4. Open GitHub and paste it
    Terminal
    open https://github.com/settings/ssh/new

Check it worked

  1. Test the connection
    Terminal
    ssh -T git@github.com

    Type "yes" if asked. You should see "Hi ! You've successfully authenticated".

Undo it
  1. Delete the key from this machine
    Terminal
    rm ~/.ssh/id_ed25519 ~/.ssh/id_ed25519.pub

    Also remove it on github.com/settings/keys.

  1. Create the key
    Terminal · Ubuntu / Debian
    ssh-keygen -t ed25519 -C "you@example.com"

    Press Enter to accept the default file. Add a passphrase if you like.

  2. Load it into the SSH agent
    Terminal · Ubuntu / Debian
    eval "$(ssh-agent -s)"
    ssh-add ~/.ssh/id_ed25519
  3. Show the public key, then copy it
    Terminal · Ubuntu / Debian
    cat ~/.ssh/id_ed25519.pub
  4. Open GitHub and paste it
    Terminal · Ubuntu / Debian
    xdg-open https://github.com/settings/ssh/new

Check it worked

  1. Test the connection
    Terminal · Ubuntu / Debian
    ssh -T git@github.com

    Type "yes" if asked. You should see "Hi ! You've successfully authenticated".

Undo it
  1. Delete the key from this machine
    Terminal · Ubuntu / Debian
    rm ~/.ssh/id_ed25519 ~/.ssh/id_ed25519.pub

    Also remove it on github.com/settings/keys.

  1. Create the key
    PowerShell
    ssh-keygen -t ed25519 -C "you@example.com"

    Press Enter to accept the default file. Add a passphrase if you like.

  2. Start the SSH agent automaticallyRun as administrator
    PowerShell
    Get-Service ssh-agent | Set-Service -StartupType Automatic
    Start-Service ssh-agent
  3. Load the key
    PowerShell
    ssh-add "$env:USERPROFILE\.ssh\id_ed25519"
  4. Copy the public key
    PowerShell
    Get-Content "$env:USERPROFILE\.ssh\id_ed25519.pub" | Set-Clipboard
  5. Open GitHub and paste it
    PowerShell
    Start-Process "https://github.com/settings/ssh/new"

Check it worked

  1. Test the connection
    PowerShell
    ssh -T git@github.com

    Type "yes" if asked. You should see "Hi ! You've successfully authenticated".

Undo it
  1. Delete the key from this machine
    PowerShell
    Remove-Item "$env:USERPROFILE\.ssh\id_ed25519", "$env:USERPROFILE\.ssh\id_ed25519.pub"

    Also remove it on github.com/settings/keys.

New to GitHub? I explain it in plain English on Layman Terms.