J86
J86

Reputation: 15237

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

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?

Upvotes: 2

Views: 4797

Answers (1)

deric4
deric4

Reputation: 1326

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.

Upvotes: 1

Related Questions