Saturday, April 24, 2010

Setup sshd on cygwin in 4 minutes

4 steps, less than 4 minutes to do,
assuming: you have cygwin installed already, plus the requisite packages.
It took me less than twenty minutes (well, I had to perform some due diligence, even though I had done it before on another system. And the windows firewall issue).
All commands should be run in a bash shell unless directed otherwise.
  1. Check that you have cygrunsrv. The brute force method:
    $ cygrunsrv.exe -S sshd
    cygrunsrv: Error starting a service: OpenService: Win32 error 1060:
    The specified service does not exist as an installed service.
    If you get 'command not found', then you'll need to install the package.
  2. run ssh-host-config
    seemed to take a minute or so before I got any output, but maybe that's because my virtual machine didn't have much entropy for key generation.
    type 'yes' a couple times at the prompts, unless you don't want to.
  3. now install as a service:
    cygrunsrv.exe -S sshd
    when asked for value of CYGWIN, you can give:
    binmode tty ntsec

  4. start the service.. run services.msc (from a cmd window) or use 'net start'

All set?
Test from bash with 'ssh -v username@localhost'.
Now, test externally with 'ssh -v username@cygwinSshHost' .. if you don't see any output, windows firewall or other form of bandaid is keeping you out.

After you're logged in, do 'ssh-add -L >> ~/.ssh/authorized_keys2' so you don't need to type passwords to log in anymore (maybe on the second login, agent forwarding doesn't happen on a new host ?).

More steps, with more detail: How to configure cygwin for sshd .

2 comments:

Saurabh said...

I was just playing around with cygwin and wanted to know how to do this. Your article really helped. Thanks.

Snaj said...

Thanks your article really helped