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
- 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.
- Install gh in PowerShell:
$ winget install --id GitHub.cli --source winget - 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 - 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
- Create a free account on github.com (how) and turn on 2FA with an authenticator app (required for contributors, see the Windows tab).
- Install gh with Homebrew:
$ brew install gh - Log in. Choose GitHub.com, SSH, and let it create and upload an SSH key:
$ gh auth login - 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)
- Create a free account on github.com (how) and turn on 2FA with an authenticator app.
- 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 - 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 - Log in. Choose GitHub.com, SSH, and let it create and upload an SSH key:
$ gh auth login - 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)
- 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 - 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.comgh says you are logged in; ssh prints "Hi USERNAME! You've successfully authenticated, but GitHub does not provide shell access."
Common errors
ghis not recognized right after winget (Windows)- Open a new terminal window, not just a new tab.
ssh -Tasks "Are you sure you want to continue connecting (yes/no)?"- Normal the first time. Type
yesand press Enter. git@github.com: Permission denied (publickey)- Your key is not on GitHub yet. Run
gh ssh-key addwith your.pubfile (see above), then tryssh -T git@github.comagain. gh ssh-key addsays 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
- GitHub Docs: Create an account
- GitHub: Pricing
- GitHub Docs: Mandatory 2FA
- gh: Install on Windows
- gh: Install on macOS
- gh: Install on Linux
- gh manual: gh auth login
- gh manual: gh ssh-key add
- GitHub Docs: Generate an SSH key
- GitHub Docs: Test your SSH connection
Checked against these pages on 2026-12-05. Tools change: if a step differs, the official page wins.