Skip to content
06Install guides · 15 min

Set up GitHub and the gh CLI

GitHub stores your projects online. The gh command logs you in from the terminal, and an SSH key lets git push without typing a password.

Roman Urdu: GitHub pe aap ka code online save hota ha. gh se terminal se login hota ha aur SSH key se baar baar password nahi dalna parta.

Cost: Free account: unlimited public and private repositories and 2,000 CI/CD minutes a month (github.com/pricing, 2026-12-05). gh is free and open source.

Windows

  1. Create a free account on github.com (how). GitHub requires two-factor authentication (2FA) for accounts that contribute code, such as making releases; you get an email and 45 days to turn it on. Set it up early with an authenticator app (TOTP), the recommended method.
  2. Install gh in PowerShell:
    $ winget install --id GitHub.cli --source winget
  3. Open a new terminal window (a new tab is not enough), then log in. Choose GitHub.com, SSH, and say yes when it offers to create and upload an SSH key:
    $ gh auth login
  4. Already have a key, or skipped that step? Make one and upload it yourself (press Enter to accept the default file):
    $ ssh-keygen -t ed25519 -C "you@example.com"
    $ gh ssh-key add $HOME\.ssh\id_ed25519.pub --title "My laptop"

macOS

  1. Create a free account on github.com (how) and turn on 2FA with an authenticator app (required for contributors, see the Windows tab).
  2. Install gh with Homebrew:
    $ brew install gh
  3. Log in. Choose GitHub.com, SSH, and let it create and upload an SSH key:
    $ gh auth login
  4. Or make and upload a key yourself:
    $ ssh-keygen -t ed25519 -C "you@example.com"
    $ gh ssh-key add ~/.ssh/id_ed25519.pub --title "My laptop"

Linux (Ubuntu/Debian)

  1. Create a free account on github.com (how) and turn on 2FA with an authenticator app.
  2. Install gh from GitHub's official apt repository (one long command, copy it whole):
    $ (type -p wget >/dev/null || (sudo apt update && sudo apt install wget -y)) && sudo mkdir -p -m 755 /etc/apt/keyrings && out=$(mktemp) && wget -nv -O$out https://cli.github.com/packages/githubcli-archive-keyring.gpg && cat $out | sudo tee /etc/apt/keyrings/githubcli-archive-keyring.gpg > /dev/null && sudo chmod go+r /etc/apt/keyrings/githubcli-archive-keyring.gpg && sudo mkdir -p -m 755 /etc/apt/sources.list.d && echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null && sudo apt update && sudo apt install gh -y
  3. Fedora (DNF5):
    $ sudo dnf install dnf5-plugins
    $ sudo dnf config-manager addrepo --from-repofile=https://cli.github.com/packages/rpm/gh-cli.repo
    $ sudo dnf install gh
  4. Log in. Choose GitHub.com, SSH, and let it create and upload an SSH key:
    $ gh auth login
  5. Or make and upload a key yourself:
    $ ssh-keygen -t ed25519 -C "you@example.com"
    $ gh ssh-key add ~/.ssh/id_ed25519.pub --title "My laptop"

Android (Termux)

  1. gh in Termux is a community package, not maintained by the GitHub CLI team, but it works for login and repos:
    $ pkg install gh openssh
  2. Log in. Choose SSH and let it create and upload a key:
    $ gh auth login

Check it worked

$ gh auth status
$ ssh -T git@github.com

gh says you are logged in; ssh prints "Hi USERNAME! You've successfully authenticated, but GitHub does not provide shell access."

Common errors

gh is not recognized right after winget (Windows)
Open a new terminal window, not just a new tab.
ssh -T asks "Are you sure you want to continue connecting (yes/no)?"
Normal the first time. Type yes and press Enter.
git@github.com: Permission denied (publickey)
Your key is not on GitHub yet. Run gh ssh-key add with your .pub file (see above), then try ssh -T git@github.com again.
gh ssh-key add says it needs the "admin:public_key" scope
Run gh auth refresh -h github.com -s admin:public_key, approve in the browser, then run the add command again.
Locked out after the 2FA deadline
Sign in and finish 2FA setup to get access back. Save the recovery codes GitHub shows you somewhere safe.

Official docs

Checked against these pages on 2026-12-05. Tools change: if a step differs, the official page wins.