.ssh / config for windows (git)
I was looking for a solution on how I can use multiple ssh keys and found 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 am using the private key to access the git server, so it looks like ssh: // git @ example.com /, it works great when I use TortoiseGit because there is an option to select the private key.
But I want to use rep git in my IntelliJ IDEA and there is only the option to use the native git shell and it also works if I put a key called id_rsa in the .ssh folder.Now I want to use multiple ssh keys (so mine the key will be named "id_rsa_test", so how do I configure the .ssh / config file on Windows to work with a regular git server?
Most of the examples I've found are for use with github only.
source to share
There is an option
that you can use in your file
and specify a key file for each host.
Host host_with_key1.net IdentityFile ~/.ssh/id_rsa Host host_with_key2.net IdentityFile ~/.ssh/id_rsa_test
More information: http://linux.die.net/man/5/ssh_config
Also take a look at http://nerderati.com/2011/03/17/simplify-your-life-with-an-ssh-config-file/
source to share
These instructions work fine on Linux. On Windows, they don't work for me today.
I found an answer that helps me, maybe the OP will help. I kissed a lot of frogs trying to work it out. You need to add a new custom key file with "ssh-add"! Here's the instruction for the magic bullet: Create a new SSH key and add it to ssh-agent . Once you know what the magic search terms are: "add a key using ssh-add to windows", you will find many other links.
If I used Windows a lot, I would find a way to make this permanent. https://github.com/elsteelbrain/ssh-agent-helper .
The ssh agent looks by default for "id_rsa" and any other keys it knows about. The key you create with a non-standard name must be added to the ssh key agent.
First, I run the key agent in the Git BASH shell:
$ eval $(ssh-agent -s) Agent pid 6276 $ ssh-add ~/.ssh/Paul_Johnson-windowsvm-20180318 Enter passphrase for /c/Users/pauljohn32/.ssh/Paul_Johnson-windowsvm-20180318: Identity added: /c/Users/pauljohn32/.ssh/Paul_Johnson-windowsvm-20180318 (/c/Users/pauljohn32/.ssh/Paul_Johnson-windowsvm-20180318)
Then I go to the directory where I want to clone the repo
$ cd ~/Documents/GIT/ $ git clone email@example.com:test/spr2018.git Cloning into 'spr2018'... remote: Counting objects: 3, done. remote: Compressing objects: 100% (2/2), done. remote: Total 3 (delta 0), reused 0 (delta 0) Receiving objects: 100% (3/3), done.
I have struggled with this for a long time.
Here are some other things I've tried along the way.
At first I was sure it had to do with file and folder permissions. On Linux I have seen the .ssh options reject if the folder is not set to 700. Windows has 711. On Windows I cannot find a way to make the permissions 700.
After struggling with this, I guess it shouldn't be a problem. That's why. If the key is named "id_rsa" then Git works! Git can connect to the server. However, if I call the key file something else and fix the config file in a consistent way no matter what, then Git fails to connect. This leads me to think that permissions are not an issue.
What you can do to debug this issue is to view the verbose output from ssh commands using the configured key.
In Git BASH shell run this
$ ssh -T git@name-of-your-server
Note. The username should be "git" here. If your key is configured and the config file is found, you can see this as I just tested it on my Linux system:
$ ssh -T firstname.lastname@example.org Welcome to GitLab, Paul E. Johnson!
On the other hand, on Windows I have the same problem as before applying "ssh-add". He wants a Git password, which always fails.
$ ssh -T email@example.com firstname.lastname@example.org password:
Again, if I manually copy my key to "id_rsa" and "id_rsa.pub" then this works great. After running ssh-add, watch Windows Git BASH win:
$ ssh -T email@example.com Welcome to GitLab, Paul E. Johnson!
You would hear me dancing with joy if you were here.
To find out what's going on you can start 'ssh' with "-Tvv"
On Linux, I see this when it succeeds:
debug1: Offering RSA public key: pauljohn@pols124 debug2: we sent a publickey packet, wait for reply debug1: Server accepts key: pkalg ssh-rsa blen 279 debug2: input_userauth_pk_ok: fp SHA256:bCoIWSXE5fkOID4Kj9Axt2UOVsRZz9JW91RQDUoasVo debug1: Authentication succeeded (publickey).
On Windows, when it fails, I see that it looks for the default names:
debug1: Found key in /c/Users/pauljohn32/.ssh/known_hosts:1 debug2: set_newkeys: mode 1 debug1: rekey after 4294967296 blocks debug1: SSH2_MSG_NEWKEYS sent debug1: expecting SSH2_MSG_NEWKEYS debug1: SSH2_MSG_NEWKEYS received debug2: set_newkeys: mode 0 debug1: rekey after 4294967296 blocks debug2: key: /c/Users/pauljohn32/.ssh/id_rsa (0x0) debug2: key: /c/Users/pauljohn32/.ssh/id_dsa (0x0) debug2: key: /c/Users/pauljohn32/.ssh/id_ecdsa (0x0) debug2: key: /c/Users/pauljohn32/.ssh/id_ed25519 (0x0) debug2: service_accept: ssh-userauth debug1: SSH2_MSG_SERVICE_ACCEPT received debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password debug1: Next authentication method: publickey debug1: Trying private key: /c/Users/pauljohn32/.ssh/id_rsa debug1: Trying private key: /c/Users/pauljohn32/.ssh/id_dsa debug1: Trying private key: /c/Users/pauljohn32/.ssh/id_ecdsa debug1: Trying private key: /c/Users/pauljohn32/.ssh/id_ed25519 debug2: we did not send a packet, disable method debug1: Next authentication method: password firstname.lastname@example.org password:
This was the hint I needed, it says it finds my ~ / .ssh / config file but never tries to use the key I want to try.
I only use Windows once for a long time and it is frustrating. Maybe people who use Windows all the time fix it and forget about it.
source to share