Setting up SSH Keys, Personal Access Tokens (PAT) and Authentication0%
Creating a Remote Repository and Connecting with git remote add

Setting up SSH Keys, Personal Access Tokens (PAT) and Authentication

Beginner12 min read•Updated: Jul 11, 2026
Study MaterialsCheatsheet

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:

  1. 1
    SSH (Secure Shell) Keys: Cryptographic public/private key pairs. Zero passwords to type; permanently secure and lightning fast.
  2. 2
    Personal Access Tokens (PAT): Scoped, revocable alphanumeric strings used as password replacements over HTTPS.

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

Bash / Terminal
ls -al ~/.ssh
# Look for id_ed25519 or id_rsa

Step 2: Generate a Modern Ed25519 Key Pair

The Ed25519 algorithm is faster and more secure than legacy RSA:

Bash / Terminal
ssh-keygen -t ed25519 -C "sumit@mskinstitute.com"
  • 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

Bash / Terminal
# Start ssh-agent in the background
eval "$(ssh-agent -s)"
 
# Add your private key
ssh-add ~/.ssh/id_ed25519

Step 4: Copy Your Public Key to Clipboard

Bash / Terminal
# On Windows PowerShell:
Get-Content ~/.ssh/id_ed25519.pub | Set-Clipboard
 
# On macOS:
pbcopy < ~/.ssh/id_ed25519.pub
 
# On Linux:
cat ~/.ssh/id_ed25519.pub

Step 5: Add Public Key to GitHub

  1. 1
    Log in to GitHub -> Click your profile avatar -> Settings.
  2. 2
    Under "Access", click SSH and GPG keys -> Click New SSH key.
  3. 3
    Provide a title (e.g. Work Laptop Windows 11).
  4. 4
    Key type: Authentication Key.
  5. 5
    Paste your copied public key into the Key box and click Add SSH key.

Step 6: Test Your SSH Connection

Bash / Terminal
ssh -T git@github.com

Expected success output:

Output
Hi sumit-msk! You've successfully authenticated, but GitHub does not provide shell access.

3. Alternative: Personal Access Tokens (PAT)

If your corporate firewall blocks outgoing SSH port 22, you can use HTTPS with a Personal Access Token:

  1. 1
    On GitHub, go to Settings -> Developer Settings -> Personal Access Tokens -> Tokens (classic).
  2. 2
    Click Generate new token (classic).
  3. 3
    Set an expiration (e.g., 90 days) and check the repo scope.
  4. 4
    Copy the token string immediately (e.g., ghp_xxxxxxxxxxxx).
  5. 5
    When Git prompts for your password in the terminal, paste the PAT string instead of your GitHub password.

Interactive Quiz

Practice Quiz

Question 1
Why did GitHub deprecate password authentication for Git operations in 2021?
Question 2
In asymmetric SSH cryptography, which key must remain strictly private and never be shared or uploaded to GitHub?
Question 3
Which command generates a secure, modern Ed25519 SSH key pair?
Question 4
How do you verify that your SSH key is successfully authenticating with GitHub?
Question 5
If you use HTTPS URLs (e.g. https://github.com/user/repo.git), what must you provide when Git prompts for your password?
Next Lesson

Creating a Remote Repository and Connecting with git remote add

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

PrevNext