Skip to content

Instantly share code, notes, and snippets.

@stephenfrench9
Last active February 15, 2023 18:57
Show Gist options
  • Save stephenfrench9/72ce3fd4f4e57c39820c5f4b2b1db963 to your computer and use it in GitHub Desktop.
Save stephenfrench9/72ce3fd4f4e57c39820c5f4b2b1db963 to your computer and use it in GitHub Desktop.
Simplified instructions to add ssh keys to Github, with optional deep dive into `git` toolchain
  1. Make a key pair
    ssh-keygen -t ed25519 -C "stephenfrench9@gmail.com" -f ~/.ssh/github
    
    (press enter instead of typing a passphrase. note that -C is just a comment)
  2. Configure your ssh tool to use the keypair by modifying ~/.ssh/config
    echo '
    HOST *github*
      AddKeysToAgent yes
      IdentityFile ~/.ssh/github
    ' >> ~/.ssh/config
    
  3. View your public key cat ~/.ssh/github.pub
  4. Go to github.com and add your public key to your account

done.

The ssh, ssh-add, ssh-agent, and git toolchain

Before you run any git commands, view your agents keys, and clear them.

ssh-add -l
ssh-add -D

Now run any git command that calls github, like git fetch, for example.

Then view your agents keys:

ssh-add -l

Summary

Clear, view, and add keys at will, just for fun.

  • Clear with ssh-add -D or eval "$(ssh-agent -s)"

  • Add with ssh-add -K ~/.ssh/github or git fetch

  • View with ssh-add -l

Excercise 1

  1. With git fetch working, delete your new entry in ~/.ssh/config. Does git fetch still work?
  2. Run ssh-add -D. How about now?
  3. Add it back in, this time omitting the line with AddKeysToAgent. Does git fetch work?
  4. Run ssh-add -D. How about now?

Excercise 2

  1. create a key with a passphrase ssh-keygen -t ed25519 -C "has_password" -f ~/.ssh/augen and enter a password
  2. ensure that ssh config calls for this key to use KeyChain
  3. Use the key (probably by adding the key to your github account and then running get fetch) and enter the password.
  4. Use the key again, note that you don't have to enter the password.
  5. ssh-add -D, and delete the password from your keychain utility (a mac app)
  6. Use again and note that now you need to reneter the key.

Sources

connecting-to-github-with-ssh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment