How to Login to GitHub from the Terminal: A Simple Guide

Accessing GitHub from the terminal is a common task for developers who want to push, pull, and manage repositories without switching to a browser. While Git itself doesn’t require a login command, authenticating your terminal with GitHub is essential for secure and smooth operations.

In this guide, you’ll learn how to authenticate with GitHub from the terminal using the recommended methods.


🧠 Why You Need to Authenticate

Git operations that communicate with GitHub—like pushing code or cloning private repositories—require authentication to verify your identity and permissions.


✅ Method 1: Use GitHub CLI (gh)

GitHub provides a powerful command-line tool called gh that helps you authenticate easily.

Step 1: Install GitHub CLI

  • macOS (Homebrew):
brew install gh
  • Windows (via Scoop or installer):
scoop install gh

Or download from https://cli.github.com.

Step 2: Authenticate with GitHub

Run:

gh auth login

Follow the interactive prompts to:

  • Choose GitHub.com or GitHub Enterprise.
  • Select HTTPS or SSH.
  • Authenticate via a web browser or paste a token.

✅ Method 2: Use Personal Access Token (PAT) for HTTPS

Since August 2021, GitHub no longer supports password authentication for Git over HTTPS. Instead, use a Personal Access Token (PAT).

Step 1: Generate a PAT

  1. Go to GitHub: https://github.com/settings/tokens
  2. Click Generate new token.
  3. Select scopes (e.g., repo for repository access).
  4. Copy the generated token securely.

Step 2: Use PAT When Prompted

When Git asks for your password during a push or pull over HTTPS, enter the PAT instead of your GitHub password.


✅ Method 3: Use SSH Keys (Recommended for Frequent Users)

SSH keys allow passwordless, secure access to GitHub.

Step 1: Generate an SSH Key (if you don’t have one)

ssh-keygen -t ed25519 -C "yo********@ex*****.com"

Or use RSA if older systems require:

ssh-keygen -t rsa -b 4096 -C "yo********@ex*****.com"

Press Enter to accept default file location and add a passphrase if desired.

Step 2: Add SSH Key to GitHub

  1. Copy your public key:
cat ~/.ssh/id_ed25519.pub
  1. Go to GitHub: https://github.com/settings/keys
  2. Click New SSH key, paste the key, and save.

Step 3: Test SSH Connection

ssh -T gi*@gi****.com

You should see a success message.


🧩 Summary

Authentication MethodHow to Use
GitHub CLIInstall gh and run gh auth login
Personal Access TokenUse token as password for HTTPS
SSH KeysGenerate keys and add to GitHub SSH keys

📌 Final Tips

  • SSH keys are great for developers who work with GitHub regularly.
  • Use GitHub CLI for a streamlined experience.
  • Always keep your tokens and keys secure.
Sharing Is Caring:

Leave a Comment