AI Hints
Home›Git & GitHub Tutorial›Pushing to GitHub
Git & GitHub · Lesson 57 of 144

Proving It Is You

Tokens and SSH keys.

⏱ 2 min read▶ Video at 1:01:17🎓 Free
Watch this lesson in the Git & GitHub courseWatch on YouTube ↗Full Git & GitHub course

GitHub won't let just anyone push to your repository. When you push, you need to prove it's you. Your normal GitHub password doesn't work in the terminal. Instead, you use a token, or an SSH key.

Proving It Is You
From the video: Proving It Is You
  • Push needs proof
  • Your password won't work
  • Use a token, or an SSH key

Two ways to sign in

Option one is HTTPS, with a personal access token. You create the token in GitHub's settings, under developer settings, and paste it when Git asks for a password. Option two is SSH. You create a key pair on your computer, and give GitHub the public half. Once it's set up, you never type anything again.

HTTPS + token

  • https://github.com/...
  • Token from GitHub settings
  • Paste it as the password

SSH key

  • git@github.com:...
  • Key pair on your computer
  • Public key added to GitHub

Making an SSH key

Here's how to make an SSH key. SSH keygen, dash t, ED two five five one nine, which is the type of key, and dash C with your email, as a label. Dash f says where to save it, and dash capital N, with empty quotes, skips the passphrase question, just for this demo. It saves two files. The one ending in dot pub is the public key. You copy its contents into GitHub, under settings, SSH and GPG keys.

git
ssh-keygen -t ed25519 -C "sam@example.com" -f ~/.ssh/id_ed25519 -N ""
Generating public/private ed25519 key pair.
Your identification has been saved in /Users/sam/.ssh/id_ed25519
Your public key has been saved in /Users/sam/.ssh/id_ed25519.pub
The key fingerprint is:
SHA256:z2a5N+uQF4DqpDrLf3aoO2tH5hhknHQn4ccCzOuKdAQ sam@example.com
The key's randomart image is:
ls ~/.ssh
id_ed25519
id_ed25519.pub
cat ~/.ssh/id_ed25519.pub
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIINa5BB5Not66R4RWZs3mNd3murZLiCHDNne2q0igWEk sam@example.com

Keep it secret

The public key is safe to share. That's its whole purpose. But the other file, without dot pub, is your private key. Never share it, never commit it, and never paste it anywhere. Anyone with it can push as you. Tools like the GitHub desktop app, or the GH command line tool, can set all of this up for you too.

.pubpublic: share it
id_ed25519private: never share
Never commityour private key
Easier setupGitHub CLI or Desktop

Summary

Use a personal access token with HTTPS, or an SSH key. Share only the public key. Next, giving your project a front page.

Key takeaways
  • HTTPS + personal access token
  • SSH: share only the .pub
  • Never share the private key
Next up: A README — your project's front page