Thursday, June 23, 2011

Debugging SSH server in Cygwin

If you are debugging a SSH connection, you may need to run sshd by hand (instead of as a service) and enable debugging output. Doing so allows you to track exactly why a connection is failing to establish. However, if you try to run sshd by hand, you may get the following message.
% cygrunsrv.exe --stop sshd
% /usr/sbin/sshd.exe -D
Could not load host key: /etc/ssh_host_ecdsa_key
/var/empty must be owned by root and not group or world-writable.
To fix this, make the user starting the sshd service the owner of /var/empty.
% ls -ld /var/empty
drwxr-xr-x+ 1 cyg_server root 0 May  7  2010 empty
% chown <user> /var/empty
Now, start sshd again.
% /usr/sbin/sshd.exe -D
When you are done debugging and are ready to run sshd again as a service, change the owner of /var/empty to cyg_server.
% chown cyg_server /var/empty
% cygrunsrv.exe --start sshd
 Note: you must have administrator privileges to run cygrunsrv.exe.

1 comment:

Dirk said...

You really want to use -d (debug, do not fork and show all log messages on stdout) instead of -D (do not fork).

Multiple -d increase verbosity, for key problems, I needed three:
/usr/sbin/sshd.exe -ddd

Note that in debug mode, the server quits after a successful logoff from the first client.

Otherwise, great tip!