Skip to main content
v2026.11,858 entries · CC-BY 4.0

How to Install GitHub CLI (gh) and Set Up SSH Keys

Install GitHub CLI on macOS, Windows or Linux, then run gh auth login to sign in and set up the SSH key GitHub needs, including headless token use.

Written and maintained by CASRAI Editorial Board

Last updated

GitHub CLI (the gh command) is installed from GitHub’s own packages: Homebrew on macOS, WinGet on Windows, or the official apt and dnf repositories on Linux. After installing, one command, gh auth login, signs you in and can create and upload the SSH key your machine needs for GitHub. The commands below follow the project’s current installation documentation, checked on 2026-10-29.

What gh is used for in research

Research code, analysis scripts, manuscripts and small datasets are often versioned on GitHub. gh brings GitHub tasks to the terminal, which matters on machines without a browser, such as a cluster login node. The project states that GitHub CLI is supported for users on GitHub.com, GitHub Enterprise Cloud and supported GitHub Enterprise Server versions, on macOS, Windows and Linux. If you are still deciding between hosting services, see Git vs GitHub vs GitLab.

Install or access (official source only)

macOS

Install with Homebrew:

brew install gh

Windows

Install with WinGet, or download the precompiled binary (MSI) from the project’s GitHub Releases page:

winget install --id GitHub.cli --source winget

The Windows installer modifies your PATH. When using Windows Terminal, you need to open a new window for the changes to take effect.

Debian, Ubuntu and Raspberry Pi OS (apt)

The project hosts signed Debian packages. Its documented install adds the signing key and repository, then installs the package:

(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 (dnf)

On 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

On DNF4:

sudo dnf install 'dnf-command(config-manager)'
sudo dnf config-manager --add-repo https://cli.github.com/packages/rpm/gh-cli.repo
sudo dnf install gh

How to install from GitHub itself

The project also publishes precompiled binaries on its GitHub Releases page, and RPM repositories for yum and zypper. Use these when no package manager above fits, for example on a managed server where you cannot add repositories.

Step-by-step: sign in and set up SSH keys for GitHub

  1. On Windows, open a new Windows Terminal window (a new tab is not enough) so the updated PATH is picked up.
  2. Run gh auth login. It authenticates with a GitHub host, and the default host is github.com. For a different host, add --hostname, for example gh auth login --hostname enterprise.internal.
  3. Choose ssh as the Git protocol when asked (or pass -p ssh). The login command then detects existing SSH keys to upload and prompts to create and upload a new key if none is found. This one flow covers both how to set up an SSH key for GitHub and how to sign in.
  4. Complete the sign-in. The default authentication mode is a web-based browser flow. Add -c (--clipboard) to copy the one-time device code, as in gh auth login --web --clipboard.

If you do not want gh to generate or upload a key, pass --skip-ssh-key, which skips the SSH key prompt.

Creating the key yourself

GitHub’s documentation for generating a key uses the Ed25519 algorithm, with an RSA fallback for older systems:

ssh-keygen -t ed25519 -C "[email protected]"
ssh-keygen -t rsa -b 4096 -C "[email protected]"

To load the key into the SSH agent, start the agent with eval "$(ssh-agent -s)" and then:

  • macOS: ssh-add --apple-use-keychain ~/.ssh/id_ed25519
  • Linux: ssh-add ~/.ssh/id_ed25519
  • Windows (PowerShell): Start-Service ssh-agent, then ssh-add c:/Users/YOU/.ssh/id_ed25519 with your own user name

Servers, HPC and CI without a browser

Use gh auth login --with-token < mytoken.txt, which reads a personal access token (classic) from standard input. The minimum scopes are repo, read:org and gist. For a fine-grained personal access token, the manual says to favour setting the GH_TOKEN environment variable instead. Tokens are stored in the system credential store; if none is available, gh falls back to a plain text file.

Output and how to read it

Once gh auth login completes with ssh selected, any later git clone over SSH can use the uploaded key. For reproducible work, record the Git protocol and host in your project’s README so collaborators set up the same way, and pair it with a locked environment such as renv for R or a shared conda environment.

Troubleshooting

gh: command not found after installing on Windows

The installer changes PATH, so open a new Windows Terminal window before trying again.

Installed gh as a snap

The project’s Linux documentation recommends never installing gh as a snap. Remove the snap and use the apt or dnf route above.

Token rejected or commands fail on permissions

Check the token has at least the repo, read:org and gist scopes, or log in again with -s (--scopes) to request the scopes you need.

Distribution packages

Packages from Arch (sudo pacman -S github-cli), Alpine (apk add github-cli), Scoop, Chocolatey, Conda and Nix are community-maintained, not GitHub-supported. Prefer the official routes when you need support.

Alternatives: other install routes

Platform Official route Command
macOS Homebrew brew install gh
Windows WinGet winget install --id GitHub.cli --source winget
Debian, Ubuntu apt repository sudo apt install gh -y (after adding the repository)
Fedora dnf repository sudo dnf install gh (after adding the repository)
Any Precompiled binaries Download from GitHub Releases

FAQ

How do I install GitHub CLI?

Use Homebrew (brew install gh) on macOS, WinGet on Windows, or the official apt or dnf repository on Linux, then run gh auth login.

How do I set up SSH keys for GitHub?

Run gh auth login and choose ssh. The command detects existing keys to upload and offers to create and upload a new one if none is found. Alternatively generate one with ssh-keygen -t ed25519 -C "[email protected]" and add it to the SSH agent.

How do I install from GitHub?

For gh, download a precompiled binary from the project’s GitHub Releases page, or use an official package repository.

Sources (official documentation)

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · free to try

Ask about How to Install GitHub CLI (gh) and Set Up SSH Keys

Ask your first 2 questions free below. Subscribers get 150 a day for $29 a month.

An AI assistant specialized in research administration. It cites the sources behind every answer, labels web answers and says when it can't answer.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays free to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →

Ask CASRAI · Regulatory Radar

Research-admin question? Get an answer that links its sources.

An AI assistant specialized in research administration. Every answer links its sources to check before you act. 2 questions free, no account. $29/month after.

  • Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.
  • Every answer numbers its sources and links each one, so you can check the source yourself.