News for hackers. Stuff that matters.
Re:Use multiple Git SSH identities on a single computer by sigmonsays on Thursday July 20, 2023 @07:19AM (#36799004)
it'd be nice if the page describes how this tool works and changes it makes.

Since it's unclear i'm not sure how this is useful.

Also you can configure the identity to use in ssh per host using aliases. If you want to switch identities globally, just load the appropriate key in ssh-agent.

here is an ssh config which binds a specific identity to personal.github.com

    Host personal.github.com
       ControlMaster no
       Hostname github.com
       IdentityFile ~/secret/keys/personal/github
       IdentitiesOnly yes
bonus points if you set IdentitiesOnly=yes globally
Re:Use multiple Git SSH identities on a single computer by klaustopher on Thursday July 20, 2023 @07:27AM (#36799049)
Been doing exactly this for years. Don't know why I'd need a CLI to switch back and forth. Once cloned using the alias and you never have to worry about it again.
Re:Use multiple Git SSH identities on a single computer by fastest963 on Thursday July 20, 2023 @07:32AM (#36799088)
This doesn't work if you're using an agent like 1Password though and it doesn't handle signing commits with the right key either.
Re:Use multiple Git SSH identities on a single computer by perdjesk on Thursday July 20, 2023 @10:20AM (#36800853)
Using git-config it is possible to configure per directory/remote URL different signing keys.

  [includeIf "gitdir:~/work/client1/"]
   path = ~/work/client1/.gitconfig
  [includeIf "gitdir:~/work/client2/"]
   path = ~/work/client2/.gitconfig

 $ cat ~/work/client1/.gitconfig
  [user]
    email = emailforclient1
    name = nameforclient1
    signingKey = 3AA5C34371567BD2
  [core]
    sshCommand = ssh -i ~/.ssh/id_client1


 $ cat ~/work/client2/.gitconfig
  [user]
    email = emailforclient2
    name = nameforclient2
    signingKey = 4BB6D45482678BE3
  [core]
    sshCommand = ssh -i ~/.ssh/id_client2


See:

- https://news.ycombinator.com/item?id=36798978

- https://git-scm.com/docs/git-config#Documentation/git-config...

Re:Use multiple Git SSH identities on a single computer by ryan-c on Thursday July 20, 2023 @07:59AM (#36799271)
You can do a bit more, even: https://rya.nc/multi-github-accts.html

    Host *.github.com
        IdentityFile ~/.ssh/%h_id_rsa
        IdentitiesOnly yes
        HostKeyAlias github.com
        ProxyCommand nc github.com 22
The `ProxyCommand` hack makes a global `ControlMaster auto` still work with a `%C` based `ControlPath`, but using `Hostname github.com` should work when using something like `%n_%p_%r`.
Re:Use multiple Git SSH identities on a single computer by Macha on Thursday July 20, 2023 @08:59AM (#36799808)
Why not just use %n in the pattern (hostname as passed on the CLI rather than evaluated in the config) and then `Hostname github.com` inside the `Host` block instead of the latter two commands?
Re:Use multiple Git SSH identities on a single computer by ryan-c on Thursday July 20, 2023 @09:35AM (#36800225)
I think you may have replied while I was editing to suggest that.
Re:Use multiple Git SSH identities on a single computer by tr3ntg on Thursday July 20, 2023 @01:04PM (#36803458)
What's this github subdomain format? Is this a real url you're matching or syntax for something else like your username / org name?
Re:Use multiple Git SSH identities on a single computer by ryan-c on Thursday July 20, 2023 @05:08PM (#36806774)
It's a fake subdomain used to select the key.