21

I have Cygwin installed on Windows 7. I made default install. I would like to use ssh config file (~/.ssh/config) to set host and options for connecting.

Normal ssh command is not able to find the config while I try to connect: ssh host If I explicitly specify config file, everything is OK: ssh -F ~/.ssh/config

I cannot found any option to set ssh client, something like /etc/ssh

Maybe ssh doesn't know where is my home folder? (I have set HOME environment variable to my home folder)

7 Answers 7

21

Install the openssh package and then run ssh-host-config. It will generate a "ssh_config" file in /etc/.

2
  • He obviously already installed the opsnssh package.
    – barlop
    Jun 23, 2022 at 23:25
  • This does not work. It generates an ssh_config file in /etc/ but ignores anything I put in it, just as it ignores anything I put in ~/.ssh/config . But it will read from /Users/<me>/.ssh/config which is not in my Cygwin home directory.
    – causative
    Jul 8 at 1:35
6

I had the same issue. I wanted to use ~/.ssh/config because I was already using that directory for other applications and didn't want to maintain 2 copies. So creating an /etc/ssh_config directory wasn't the ideal solution.

As Fujimoto Youichi mentions, ssh looks at /etc/passwd for your home directory and not the $HOME environment variable.

The current cygwin versions (I'm using 2.6) no longer creates /etc/passwd as part of the install. However, it is easy to create a new one:

    mkpasswd -c -p "$(cygpath -H)" > /etc/passwd
  • -c Adds the current user to the passwd file
  • -p "$(cygpath -H)" Adds your current home directory

https://cygwin.com/cygwin-ug-net/mkpasswd.html has more details on the available flags.

I haven't looked at the code, but ssh's preference seems to be:

  1. /etc/ssh_config
  2. ~/.ssh/config

So if you only want to use the ssh configuration information from ~/.ssh/config, then be sure to delete /etc/ssh_config.

Also, be sure to open a new cygwin terminal window after making changes, for them to become available.

1
  • seems it's been relocated to /etc/defaults/ssh_config
    – VeraKozya
    Feb 4, 2019 at 19:40
3

ssh command looks for its config file under home directory from /etc/passwd. So setting HOME variable will not work.

There are many ways but we can fix it by simply making a symlink as follows.

ln -s ~ /home

0
2

According to the accepted answer, by use command to initialize:

ssh-host-config

You can also create empty /etc/ssh_config in Cygwin, which will work same.

The /etc/ssh_config creating by ssh-host-config is also empty with all comment out lines.


Reload SSH with new config:

To effect config, you can just finish editing /etc/ssh_config without restart service.

5
  • 1
    How does this differ from the accepted answer? Jun 15, 2017 at 4:05
  • I can not comment on it to further explain the principle and how to effect the ssh config.
    – Nick Tsai
    Jun 15, 2017 at 5:27
  • You need to earn some reputation first. Try editing some badly formatted posts, or answering an unanswered question :-) Jun 15, 2017 at 5:28
  • OK! I posted this answer because after checking the accepted answer, I did more survey on it. Thank you.
    – Nick Tsai
    Jun 15, 2017 at 5:32
  • 1
    This is written so much better than the accepted answer. e.g. the accepted answer talks of installing openssh which is ridiculous 'cos obviously it's already installed . This one is very to the point
    – barlop
    Jun 23, 2022 at 23:26
0

The other answers didn't work for me. I just created c:\cygwin64\etc\ssh_config and pasted in the following default / example file:

# This is the ssh client system-wide configuration file.  See
# ssh_config(5) for more information.  This file provides defaults for
# users, and the values can be changed in per-user configuration files
# or on the command line.

# Configuration data is parsed as follows:
#  1. command line options
#  2. user-specific file
#  3. system-wide file
# Any configuration value is only changed the first time it is set.
# Thus, host-specific definitions should be at the beginning of the
# configuration file, and defaults at the end.

# Site-wide defaults for some commonly used options.  For a comprehensive
# list of available options, their meanings and defaults, please see the
# ssh_config(5) man page.

# Host *
#   ForwardAgent no
#   ForwardX11 no
#   RhostsRSAAuthentication no
#   RSAAuthentication yes
#   PasswordAuthentication yes
#   HostbasedAuthentication no
#   GSSAPIAuthentication no
#   GSSAPIDelegateCredentials no
#   BatchMode no
#   CheckHostIP yes
#   AddressFamily any
#   ConnectTimeout 0
#   StrictHostKeyChecking ask
#   IdentityFile ~/.ssh/identity
#   IdentityFile ~/.ssh/id_rsa
#   IdentityFile ~/.ssh/id_dsa
#   Port 22
#   Protocol 2,1
#   Cipher 3des
#   Ciphers aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc
#   MACs hmac-md5,hmac-sha1,[email protected],hmac-ripemd160
#   EscapeChar ~
#   Tunnel no
#   TunnelDevice any:any
#   PermitLocalCommand no
#   VisualHostKey no
#   ProxyCommand ssh -q -W %h:%p gateway.example.com
#
#
Host *
    Port 22

Hope that helps the next person.

0

Cygwin ssh expects the config to be in /home/$USER. But the home directory "~" in cygwin is C:/Users/$USER, indeed /home is empty. You can have both C:/Users/$USER/.ssh and /home/$USER/.ssh be valid paths, by creating a symlink:

ln -s ~ /home/$USER
0

The currently accepted answer did not fix the problem for me. Instead I symlinked the .ssh directory from my Windows user account's home directory into my Cygwin user's home directory:

ln -s /cygdrive/c/Users/<MY-USER>/.ssh /home/<MY-USER>/.ssh

You must log in to answer this question.

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