Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.ssh/config file for windows (git)

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://[email protected]/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.

like image 747
mathew11 Avatar asked Oct 08 '14 21:10

mathew11


People also ask

Where can I find SSH config file?

The SSH server has its own set of configuration files, including the SSH server system-wide configuration file named sshd_config. By default, these files reside in the /etc/ssh directory on the remote host.

Does Git for Windows install SSH?

Yes, Git for Windows installs its own SSH client. It ships a version of OpenSSH with the package. If you're seeing /usr/bin/ssh when you run command -v ssh , then you're using the version from Git for Windows.


2 Answers

If you use "Git for Windows"

>cd c:\Program Files\Git\etc\ssh\ 

add to ssh_config following:

AddKeysToAgent yes IdentityFile ~/.ssh/id_rsa IdentityFile ~/.ssh/id_rsa_test 

ps. you need ssh version >= 7.2 (date of release 2016-02-28)

like image 163
LennyLip Avatar answered Oct 12 '22 12:10

LennyLip


You can use multiple ssh keys on Windows 10 and specify the type of access allowed.

Assuming you have created the ssh secure keys already and they were stored in C:\Users\[User]\.ssh

  1. Open the folder C:\Users\[User]\.ssh

  2. Create the file config (no file extension)

  3. Open the file in a text editor like Notepad, and add these configuration details for the first remote host and user. Keep both CMD and BASH paths or only pick one format. Then copy-and-paste below it for the other host/user combinations and amend as required. Save the file.

    Host [git.domain.com] User [user] Port [number] IdentitiesOnly=yes PreferredAuthentications publickey PasswordAuthentication no # CMD IdentityFile C:\Users\[User]\.ssh\[name_of_PRIVATE_key_file] # BASH IdentityFile /c/Users/[User]/.ssh/[name_of_PRIVATE_key_file] 
  4. Testing

  • Using Bash (Git for Windows)
    $ ssh -T git@[git.domain.com] Welcome to GitLab, @[User]! 
  • Using Commandline (requires activation of Win 10 OpenSSH Client)
    C:\Users\[User]>ssh -T git@[git.domain.com] Welcome to GitLab, @[User]! 
  1. For troubleshooting use ssh -Tv git@[git.domain.com] (or -Tvv or -Tvvv for higher verbosity levels).
like image 38
Sven Haile Avatar answered Oct 12 '22 12:10

Sven Haile