Setting up SSH Keys, Personal Access Tokens (PAT) and Authentication
Setting up SSH Keys, Personal Access Tokens (PAT) and Authentication
To push code from your local machine to GitHub, Git must authenticate your identity. In August 2021, GitHub permanently removed support for plain account passwords when authenticating Git operations over HTTPS. Today, you must authenticate using either SSH Keys (recommended) or Personal Access Tokens (PAT).
1. Why Password Authentication Was Deprecated
Plain text passwords suffer from major security flaws:
- They can be intercepted, shoulder-surfed, or phished.
- A leaked password grants full access to your entire GitHub account.
- They cannot be easily scoped or set to expire automatically.
Modern Solutions:
- 1SSH (Secure Shell) Keys: Cryptographic public/private key pairs. Zero passwords to type; permanently secure and lightning fast.
- 2Personal Access Tokens (PAT): Scoped, revocable alphanumeric strings used as password replacements over HTTPS.
2. Generating and Configuring SSH Keys (Recommended)
SSH uses asymmetric public-key cryptography. You keep the private key secret on your laptop, and upload the public key (.pub) to GitHub.
Step 1: Check for Existing SSH Keys
Step 2: Generate a Modern Ed25519 Key Pair
The Ed25519 algorithm is faster and more secure than legacy RSA:
- Press Enter to accept the default file location (
~/.ssh/id_ed25519). - Enter a passphrase for extra local security (or press Enter for no passphrase).
Step 3: Add Your Private Key to the SSH Agent
Step 4: Copy Your Public Key to Clipboard
Step 5: Add Public Key to GitHub
- 1Log in to GitHub -> Click your profile avatar -> Settings.
- 2Under "Access", click SSH and GPG keys -> Click New SSH key.
- 3Provide a title (e.g.
Work Laptop Windows 11). - 4Key type: Authentication Key.
- 5Paste your copied public key into the Key box and click Add SSH key.
Step 6: Test Your SSH Connection
Expected success output:
3. Alternative: Personal Access Tokens (PAT)
If your corporate firewall blocks outgoing SSH port 22, you can use HTTPS with a Personal Access Token:
- 1On GitHub, go to Settings -> Developer Settings -> Personal Access Tokens -> Tokens (classic).
- 2Click Generate new token (classic).
- 3Set an expiration (e.g., 90 days) and check the
reposcope. - 4Copy the token string immediately (e.g.,
ghp_xxxxxxxxxxxx). - 5When Git prompts for your password in the terminal, paste the PAT string instead of your GitHub password.
Practice Quiz
https://github.com/user/repo.git), what must you provide when Git prompts for your password?Creating a Remote Repository and Connecting with git remote add
Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
Related Lessons
Practice Quiz
Test your understanding of this lesson with 5 questions. Each question has one correct answer.