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.
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
bonus points if you set IdentitiesOnly=yes globally