Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I tell the GitHub CLI to use a specific SSH key?

Tags:

ssh

github-cli

I have various GitHub accounts and for each account I have SSH set up. So under ~/.ssh I have a public and private key for each account.

I want to use the GitHub CLI, but I am not sure how I can tell the CLI to use a particular SSH key.

In case it is relevant, this is what I get when I run ssh-add -l:

enter image description here

Example Scenario

I want to run gh repo create on GitHub account B, but for some reason, the repo got created on GitHub account A. Is there a way I can tell gh what account to use?

like image 628
J86 Avatar asked Jun 11 '26 14:06

J86


1 Answers

if you have different GitHub users the gh-cli won't be very effective. as @phd commands like gh repo create require logging in via an auth token. https://cli.github.com/manual/gh_auth_login

Switching contexts between accounts (i.e. github.com/user1 and github.com/user2) def doesn't seem supported so you'd have to hack around loging in and out each time every time you switched.

But configuring which ssh key git should use can be configured easily enough in some combo of ~/.ssh/config .gitconfig and/or setting the GIT_SSH_COMMAND env var before running git commands.

like image 59
deric4 Avatar answered Jun 14 '26 05:06

deric4