3

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?

6
  • Does Github CLI (gh) uses ssh protocol at all? Do you mean git command line? Git is not Github CLI but can be used with Github. Commented Dec 1, 2022 at 15:47
  • Yeah, you can make it use ssh via git config set. Yep I'm talking about gh (the CLI, I know Git and the GitHub CLI are two different things). Commented Dec 1, 2022 at 15:56
  • 2
    If you mean gh config set git_protocol ssh — that's not about Github CLI, it's the protocol to use for git clone and push operations. See cli.github.com/manual/gh_config. So the question remains: are you talking about using gh with SSH or git? Commented Dec 1, 2022 at 16:06
  • Good catch! I'm still talking about gh though. Commented Dec 1, 2022 at 21:04
  • 2
    I don't think gh repo create runs over SSH. It's a Github API call so it runs over HTTPS. You need gh auth logout and gh auth login. Commented Dec 1, 2022 at 21:31

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, so it isn't currently supported.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.