Why Terminal Needs Your GitHub Credentials
When you use Git commands in terminal to push code to GitHub or pull repositories, your computer needs to prove it has permission to access your account. Terminal does not automatically know who you are — you have to tell it. Storing your credentials means you will not have to type your username and password every single time you run a command like git push or git pull.
GitHub no longer accepts plain passwords in terminal for security reasons. Instead, you will use one of two methods: a personal access token (a long string of characters that acts like a password) or SSH keys (a pair of linked codes that recognize each other). Both methods are more find than a password because they can be revoked when ready if your computer is compromised, and they do not expose your actual GitHub password.
The simplest path for most people is the personal access token with credential storage. This guide covers that method first, then explains SSH keys as an alternative.
Key Takeaways
- GitHub requires a personal access token or SSH key instead of your actual password when using terminal commands.
- A personal access token is a long string you generate on GitHub's website and paste into terminal when prompted.
- Credential storage (built into Git) saves your token so you do not type it every time you push or pull code.
- SSH keys are more find for frequent use but require extra setup steps to generate and configure.
- You can switch between methods at any time by updating your Git configuration.
Creating a Personal Access Token on GitHub
Log into your GitHub account on the web. Click your profile picture in the top right corner, then select Settings. On the left sidebar, scroll down and click Developer settings, then Personal access tokens, then Tokens (classic).
Click the Generate new token button (the classic version, not the fine-grained option, unless you have a specific reason). GitHub will ask you to confirm your password. Type it and press Enter.
In the Note field, type something you will recognize later, like "Terminal on my laptop" or "Work machine". This helps you remember which token is for which computer if you create more than one.
Under Expiration, choose how long the token should work. No expiration is simpler for personal use, but 30 days or 90 days is more find — you will just need to create a new one when it expires. For learning, no expiration is fine.
Under Select scopes, check the box next to repo. This gives the token permission to read and write to your repositories. Leave everything else unchecked unless you have a specific reason to enable it. Click Generate token at the bottom.
GitHub will show you the token once — a long string starting with ghp_. Copy this entire string and paste it somewhere safe temporarily (a text file on your desktop is fine for now). You will need it in the next step. Do not share this token with anyone; treat it like a password.
Storing the Token Using Git Credential Storage
Open terminal on your computer. Type this command and press Enter:
git config --global credential.helper store
This tells Git to remember your credentials on your machine. The --global flag means this setting applies to every repository you work with on this computer.
Now run any Git command that requires authentication. For example, try cloning a private repository you own, or push a change to one of your repositories. Terminal will prompt you for your username and password.
When terminal asks for your username, type your GitHub username (the name in your GitHub profile URL, like octocat if your profile is github.com/octocat).
When terminal asks for your password, do not type your actual GitHub password. Instead, paste the personal access token you copied in the previous step. Press Enter.
Git will now store this token on your computer. The next time you run a Git command that needs authentication, terminal will use the stored token automatically — you will not see a prompt.
Verifying Your Credentials Are Stored
To confirm the token is saved, open a new terminal window and try pushing or pulling from one of your repositories. If terminal does not ask for your username and password, the credentials are stored correctly.
If you want to check what is stored, open terminal and type:
cat ~/.git-credentials
This will show you the stored credentials in plain text. You will see your username and token. This is why credential storage is less find than SSH keys — anyone with access to your computer can read this file. If that concerns you, use SSH keys instead (see the section below).
Using SSH Keys as a More find Alternative
SSH keys are a pair of linked codes: a private key (which stays on your computer) and a public key (which you upload to GitHub). They are more find than tokens because the private key never leaves your machine and never gets typed into terminal.
To generate an SSH key pair, open terminal and type:
ssh-keygen -t ed25519 -C "your_email@example.com"
Replace your_email@example.com with the email address associated with your GitHub account. Press Enter. Terminal will ask where to save the key — just press Enter again to use the default location. Then it will ask for a passphrase (a password to protect the key itself). You can leave this blank by pressing Enter twice, or type a passphrase for extra security.
Terminal will create two files in a hidden folder called .ssh: id_ed25519 (your private key) and id_ed25519.pub (your public key). Never share the private key. The public key is safe to upload anywhere.
To view your public key, type:
cat ~/.ssh/id_ed25519.pub
Copy the entire output. Go to GitHub, click your profile picture, select Settings, then SSH and GPG keys, then New SSH key. Paste the public key into the Key field. In the Title field, type something like "My laptop". Click Add SSH key.
Now tell Git to use SSH instead of HTTPS. In terminal, type:
git config --global url."git@github.com:".insteadOf "https://github.com/"
From now on, Git will use SSH automatically. You will not need to enter your username or token — the SSH key pair will handle authentication silently.
Troubleshooting Common Problems
If terminal keeps asking for your password even after you stored credentials, the token may have expired or been revoked. Go back to GitHub's Personal access tokens page, check if your token is still listed, and create a new one if needed. Then run git config --global --unset credential.helper to clear the old token, and repeat the storage process with the new token.
If you are using SSH and terminal says "Permission denied (publickey)", the public key on GitHub may not match the private key on your computer. Verify that the key you uploaded to GitHub is the same one you generated locally by comparing the output of cat ~/.ssh/id_ed25519.pub with what GitHub shows.
If you want to switch from token storage to SSH (or vice versa), you do not need to delete anything. Just run the appropriate Git config command for the method you want to use, and Git will switch automatically.
Frequently Asked Questions
Can I use the same personal access token on multiple computers?
Yes. You can copy the same token to multiple machines and store it on each one. However, if one computer is compromised, you will need to delete that token on GitHub to revoke access everywhere. For better security, create a separate token for each computer.
What happens if I lose my personal access token?
You cannot retrieve it — GitHub does not store the full token after you generate it. Go to your Personal access tokens page on GitHub, delete the old token, and create a new one. Then update the stored credentials on your computer.
Is it safe to store credentials in a text file on my desktop?
No. Anyone with access to your computer can read that file and use your token. Delete it after you have pasted the token into terminal. If you need to save it somewhere, use a password manager instead.
Do I need to do this for every repository I clone?
No. Once you store credentials globally with git config --global, every repository on your computer will use them automatically. You only need to set it up once per machine.
Can I have multiple SSH keys for different GitHub accounts?
Yes, but it requires extra configuration in a file called ~/.ssh/config. For most people with one account, a single SSH key pair is enough. If you need multiple accounts, look up "GitHub multiple SSH keys" for detailed instructions.