5

Cygwin's ssh isn't reading my config file at %HOME%/.ssh/config.

I have Cygwin installed, but I prefer to use the DOS-like environment on Windows. I have the Cygwin bin directory in my PATH and I often use the Unix-like commands outside of Cygwin.

Since I'm not logging in to Cygwin (or executing .bashrc), I expected the commands to use the environment variables set by Windows. HOME is set to C:\Users\Vince and I expected ssh to find the config file in C:\Users\Vince\.ssh\config, but that doesn't happen unless I use the -F option to tell it to look there.

How do I tell where Cygwin's ssh is looking for the config file? Can that be changed?

Thank you.

5
  • 1
    What is the output of echo $HOME in Cygwin? The ssh config will be loaded from ~/.ssh/config, which may be different then %HOME/.ssh/config.
    – Matt Clark
    Commented Jan 14, 2016 at 2:43
  • @MattClark If I open the "Cygwin64 Terminal" shortcut created by Cygwin setup (runs C:\cygwin64\bin\mintty.exe -i /Cygwin-Terminal.ico -), echo $HOME shows "/home/Vince" (real directory is C:\cygwin64\home\Vince). If I run C:\cygwin64\Cygwin.bat (runs bash --login -i), it shows "/cygdrive/c/Users/Vince". I don't understand why MinTTY does something different. Both commands effectively run bash as an interactive login shell. The bash man page says that it uses the value of the HOME variable when performing tilde expansion.
    – Vince
    Commented Jan 14, 2016 at 3:12
  • It is indeed looking in C:\cygwin64\home\Vince\.ssh. When I copied the config file there from C:\Users\Vince\.ssh, it worked. I'm not sure this is a solution, though. I'd rather not have two copies of the config file (one for git and one for ssh). I also don't understand how ssh knows where the Cygwin user's home directory is. In the ssh man page, it says that the default location of the config file is ~/.ssh/config, but tilde expansion is performed by the bash shell that isn't running.
    – Vince
    Commented Jan 14, 2016 at 3:22
  • And a sort of a workaround that seems less likely to break something... In Cygwin Terminal: rm -rf ~/.ssh ln -s /cygdrive/c/Users/Vince/.ssh
    – Vince
    Commented Jan 14, 2016 at 5:48
  • In the beginning I think I just symlined my whole user directory, /home/me -> /cygdrive/c/Users/me. I was trying to get it to work the proper way :/
    – Matt Clark
    Commented Jan 14, 2016 at 5:53

4 Answers 4

9

Here is my answer based on the q&a we had in the comments.

By default, Cygwin will create a user home directory in /home/User, on a windows system, out home directory is somewhere else -

To fix this, open /etc/nsswitch.conf and edit in this line

db_home: windows

Close all Cygwin terminal sessions and relaunch. Now again echo $HOME and you should see that it should now be set to the windows %HOME%, and no longer use the one located in /home

edit

You may also need to remove

/etc/passwd
/etc/group

As this should now be deferred to windows.

2
  • 2
    Adding the entry to nsswitch.conf worked, but only after removing (renaming, actually) /etc/passwd and /etc/group. Apparently, it reads those first, then uses nsswitch.conf as a fallback. Some documentation seems to suggest that it's configurable with nsswitch.conf, but it didn't work for me without deleting passwd and group. Just to summarize what I tested: 1) modify nsswitch.conf; doesn't work. 2) remove passwd, group; doesn't work. 3) remove passwd, group, and modify nsswitch.conf; works.
    – Vince
    Commented Jan 14, 2016 at 5:43
  • huh, interesting. I guess I am missing those... :p Good catch, I added it into my answer.
    – Matt Clark
    Commented Jan 14, 2016 at 5:52
0

To verify if Cygwin (cygrunsrv) is installed properly, run C:\cygwin\Cygwin.bat, and execute the following command:

cygrunsrv -h

If Cygwin is installed properly, then all the Cygwin help options are displayed on the screen. However, if this command returns an error message, then you may have to reinstall Cygwin.

To configure the SSHD service, run C:\cygwin\Cygwin.bat, and execute the following command:

ssh-host-config

After running the command, you are prompted the following questions:

  • Query: Should privilege separation be used? : yes
  • Query: New local account 'sshd'? : yes
  • Query: Do you want to install sshd as a service?
  • Query: : yes
  • Query: Enter the value of CYGWIN for the deamon: [] binmode ntsec
  • Query: Do you want to use a different name? (yes/no) yes/no

At this point, if you want to use the same name, that is cyg_server, enter no. You are then prompted the following questions:

  • Query: Create new privileged user account 'cyg_server'? (yes/no) yes
  • Query: Please enter the password:
  • Query: Renter:

However, if you want to use a different name, enter yes. You are then prompted the following questions:

  • Query: Enter the new user name: cyg_server1
  • Query: Reenter: cyg_server1
  • Query: Create new privileged user account 'cyg_server1'? (yes/no) yes
  • Query: Please enter the password:
  • Query: Reenter:

If the configuration is successful, you will see the following message:

Host configuration finished. Have fun!

1
  • 1
    I'm not sure how this is related to my question. I don't want to run an ssh server on my Windows box. I just want to know where the ssh client looks for the .ssh directory.
    – Vince
    Commented Jan 14, 2016 at 2:52
0

Part of the problem here is the fractured, overloaded meanings assigned to $HOME. Trying to mash all your user information into a single directory when you are mixing Cygwin and Windows is a bad idea (tm).

You get away with having multiple "systems" as long as they don't conflict. When you try to make them cohabit too closely, you get unresolvable problems. This is why bash, ksh and zsh have their own profiles, they are not 100% compatible.

Having a separate /home/USERNAME directory for CYGWIN is a good idea. When there are things that you know are compatible and should be shared, then you can take steps to make it accessible from both worlds. If you're just starting with Cygwin, you shouldn't try to make it too cozy with Windows.

Windows doesn't normally have a HOME directory, but some software is looking for it. The problem is you really have two homes. Dance carefully.

1
  • Windows does have a HOME directory (open up cmd.exe and type echo %HOME%). And it's not clear what the problem is in having your Windows home director and your Cygwin home directory be the same. Commented May 25, 2016 at 16:37
0

I had same problem.

At the end I didn't use the openssh package from Cygwin, but I was using ssh command of the Windows. So install Cygwin's openssh package, and that's all.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .