I've been looking for a solution on how I can use multiple ssh keys and I figured out, that it will work with a config file in the .ssh directory, but it doesn't work on windows.
My problem is that I'm using a private key to access a git server, so it looks like this: ssh://git@example.com/directory , it works fine when I'm using TortoiseGit, 'cause there is a possibility to choose the private key.
But I want to use the git rep in my IntelliJ IDEA and there is just the option to use the git native shell and it also works, if I put the key, called id_rsa ,into the .ssh folder. Now I want to use multiple ssh keys (so my key will get the name "id_rsa_test", so how do I configure the .ssh/config file under Windows, that it works with a usual git server?
The most examples I found yet are just for the use with github.
These instructions work fine in Linux. In Windows, they are not working for me today.
I found an answer that helps for me, maybe this will help OP. I kissed a lot of frogs trying to solve this. You need to add your new non-standard-named key file with "ssh-add"! Here's instruction for the magic bullet: Generating a new SSH key and adding it to the ssh-agent. Once you know the magic search terms are "add key with ssh-add in windows" you find plenty of other links.
If I were using Windows often, I'd find some way to make this permanent. https://github.com/raeesbhatti/ssh-agent-helper.
The ssh key agent looks for default "id_rsa" and other keys it knows about. The key you create with a non-standard name must be added to the ssh key agent.
First, I start the key agent in the Git BASH shell:
Then I change to the directory where I want to clone the repo
I fought with this for a long long time.
Here are other things I tried along the way
At first I was certain it is because of file and folder permissions. On Linux, I have seen .ssh settings rejected if the folder is not set at 700. Windows has 711. In Windows, I cannot find any way to make permissions 700.
After fighting with that, I think it must not be the problem. Here's why. If the key is named "id_rsa" then git works! Git is able to connect to server. However, if I name the key file something else, and fix the config file in a consistent way, no matter what, then git fails to connect. That makes me think permissions are not the problem.
A thing you can do to debug this problem is to watch verbose output from ssh commands using the configured key.
In the git bash shell, run this
Note, the user name should be "git" here. If your key is set up and the config file is found, you see this, as I just tested in my Linux system:
On the other hand, in Windows I have same trouble you do before applying "ssh-add". It wants git's password, which is always a fail.
Again, If i manually copy my key to "id_rsa" and "id_rsa.pub", then this works fine. After running ssh-add, observe the victory in Windows Git BASH:
You would hear the sound of me dancing with joy if you were here.
To figure out what was going wrong, you can I run 'ssh' with "-Tvv"
In Linux, I see this when it succeeds:
In Windows, when this fails, I see it looking for default names:
That was the hint I needed, it says it finds my ~/.ssh/config file but never tries the key I want it to try.
I only use Windows once in a long while and it is frustrating. Maybe the people who use Windows all the time fix this and forget it.
There is an option
IdentityFile
which you can use in your~/.ssh/config
file and specify key file for each host.More info: http://linux.die.net/man/5/ssh_config
Also look at http://nerderati.com/2011/03/17/simplify-your-life-with-an-ssh-config-file/
If you use "Git for Windows"
add to ssh_config following:
ps. you need ssh version >= 7.2 (date of release 2016-02-28)