Reputation: 1474
How can I see which SSH key file is used in Git Bash?
I tried "git config --get-all", but I get the error message
error: wrong number of arguments; usage: git config [options]
Upvotes: 99
Views: 186583
Reputation: 4406
For a one-time check, you can use ssh -v [email protected]
searching for "Server accepts key". However, for programmatic use, that may not be an option.
If you're using openssh, you can use the -G
option, which prints configuration without actually attempting to connect. It looks like this:
ssh -G [email protected] 2>/dev/null | grep -im1 '^IdentityFile' | cut -d' ' -f2
If you don't have any configured keys that are rejected by the host, then this solution should always work, and be much faster to run than ssh -v …
Upvotes: 0
Reputation: 4312
Another solution, in the latest Git Bash, you can type:
$ git-gui
Then a GUI application is executing, and in the GUI, you can just click Help → Show SSH Key to show your SSH key.
Upvotes: 77
Reputation: 18530
Which SSH key is used isn't determined by Git, but by the SSH client itself. Either the appropriate key is configured in ~/.ssh/config
, or ssh
just tries all keys it can find when connecting to the host. You can see which key ultimately succeeded by connecting to the host with the standard SSH client. For example, when using GitHub:
ssh -v [email protected]
This will give you something a bit like this:
[...]
debug1: Offering RSA public key: /home/me/.ssh/id_rsa
debug1: Authentications that can continue: publickey
debug1: Offering RSA public key: /home/me/.ssh/id_rsa2
debug1: Server accepts key: pkalg ssh-rsa blen ****
[...]
This tells you that the key .../id_rsa2
was the one accepted by the server.
Upvotes: 143