SSH Keys and Tokens
GitHub no longer accepts your account password for git push. Use the browser sign-in, an SSH key or a token instead.
On this page · 5 min · Advanced
On this page
- Learning objectives
- Explanation
- Step-by-step screens
- Code example
- Step by step
- Real-world use
- Common mistakes
- Best practices
- Remember this
- Practice exercise
- Mini quiz
- Related topics
- My notes
- Reading time
- 5 min
- Difficulty
- Advanced
- Updated
- Nov 25, 2026
Learning objectives#
- Understand the three ways to authenticate
- Create and add an SSH key
- Create a fine-grained personal access token
- Keep credentials safe
Explanation#
HTTPS + Git Credential Manager (installed with Git for Windows) is the easiest: the first push opens a browser to sign in, and the credential is stored securely.
SSH keys: ssh-keygen -t ed25519 creates a key pair. Add the public key (.pub) in GitHub → Settings → SSH and GPG keys. Clone with git@github.com:… URLs and you are never asked again.
Personal access tokens are passwords for scripts and tools. Prefer fine-grained tokens: limit them to specific repositories, give only the permissions needed (for example Contents: Read and write) and set an expiry date.
Never commit keys or tokens. If one leaks, delete it on GitHub immediately and create a new one.
Step-by-step screens#
Drawings of github.com, the Git installer, VS Code and a terminal. GitHub changes its layout from time to time; the button names stay the same. The red numbers match the numbered actions under each picture; names on your computer will differ.
Loading pictures…
Code example: Set up SSH and test it#
ssh-keygen -t ed25519 -C "asha@example.com" # press Enter for the default file
cat ~/.ssh/id_ed25519.pub # copy this into GitHub → Settings → SSH and GPG keys
ssh -T git@github.com
git remote set-url origin git@github.com:asha/hello-github.git
Hi asha! You've successfully authenticated, but GitHub does not provide shell access.
This example is illustrative. Copy or download it and run it in your own environment; the expected output is shown above.
Step-by-step explanation#
- ssh-keygen creates a private key and a .pub public key.
- Only the .pub file is copied to GitHub.
- ssh -T tests the connection.
- set-url switches an existing clone from HTTPS to SSH.
Real-world use case#
A deployment script uses a fine-grained token that can only read one repository and expires in 90 days — a leak would expose very little.
Common mistakes#
Only id_ed25519.pub goes to GitHub. The file without .pub never leaves your computer.
They can do anything forever. Use fine-grained tokens with an expiry.
Best practices#
- HTTPS + browser sign-in for beginners
- SSH for daily work
- Fine-grained tokens with expiry for scripts
- Revoke anything that leaks
Remember this#
Passwords don’t work for git push.
SSH: add the .pub key.
Tokens: fine-grained, few permissions, expiry.
Practice exercise#
Your task: Test whether your SSH key works with GitHub.
Show solution
ssh -T git@github.com
Mini quiz#
Which file do you add to GitHub?
Want more? Practise all Git & GitHub MCQs · Git & GitHub interview questions
My notes#
Saved in this browser.