World map

 

BM: Baca dalam Bahasa Melayu

World 4: Hello GitHub

SSH keys and gh auth login

You will learn: how to let your computer prove who you are, with a key pair or with gh.

The problem

You push many times a day. Can your laptop prove it’s you, with nothing to type?

Pick one answer.

Watch

Think of a padlock and its key. Give GitHub the padlock. Keep the key. An SSH key: A key pair. The private key stays on your computer. The public key goes to GitHub. works the same way. Sort the two halves.

Drag a card into a box. Or tap the card, then tap the box.

      Try it

      Build the command that makes a new key pair.

      Tap the pieces in the right order.

      …

      Watch

      bash
      ssh-keygen -t ed25519 -C "you@example.com"
      Generating public/private ed25519 key pair.
      cat ~/.ssh/id_ed25519.pub
      ssh-ed25519 AAAA...FAKE-EXAMPLE-KEY... you@example.com
      ssh-keygen starts making an ed25519 key pair. Then cat shows the public key: one long line that ends with your email. The key here is a fake example.

      It asks where to save. Press Enter for the usual place. Then pick a passphrase: a password for the key itself. cat prints the public key to copy.

      Predict

      GitHub has your padlock now. Which remote address uses SSH?

      Pick one answer.

      Watch

      bash
      ssh -T git@github.com
      Hi you! You've successfully authenticated, but GitHub does not provide shell access.
      ssh -T git@github.com answers: Hi you! You've successfully authenticated, but GitHub does not provide shell access.

      Paste the .pub key in GitHub: Settings, then SSH and GPG keys. Then test it. “Hi you!” means the padlock fits.

      Check

      Key habits: good, or needs work? Swipe each one.

      Swipe right for good, left for needs work. Or use the buttons.

      1 / 4

      Protect your key with a passphrase

      Protect your key with a passphrase

      Watch

      bash
      gh auth login
      The command gh auth login. It asks a few questions and signs you in with your browser.

      Shortcut: the GitHub CLI (gh): A free tool that talks to GitHub from your terminal. Its command is gh.. Run gh auth login. Pick GitHub.com, then HTTPS or SSH. Sign in with your browser. It can set up Git for you too.

      Try it

      Pick one way and do it for real. Tick each step.

      Mission: Git signs in by itself

      1. ssh-keygen -t ed25519 -C "you@example.com"
      2. cat ~/.ssh/id_ed25519.pub
      3. ssh -T git@github.com

      0 of 5 steps done · Your ticks are saved.

      You did it!

      You can now connect to GitHub with an SSH key or gh.

      Go deeper (optional)

      Already have an HTTPS remote? Switch it: git remote set-url origin git@github.com:you/diary.git. The ssh-agent can remember your passphrase for a whole session. The first SSH test asks you to trust github.com. Check its fingerprint on docs.github.com first.