Wednesday 15 February 2012

Running SSH daemon in Windows 7

Despite being Linux (fan)boy generally and running Fedora on all in-house laptops, I've decided to keep Windows 7 on my newly acquired Acer Revo RL100 media centre PC. I am fairly happy with it and don't feel the need to switch to Linux distro on such PC anyway. However, since my (ir)regular backup policy heavily relies on rsync which pushes data from my laptop over ssh to external USB drive attached to media centre PC, I was looking for a solution that works in Windows 7. Surprisingly, there is one and works pretty well. Phew!

Firstly, full credit for the solution below goes to Chris Galpin over at Code Optimism blog. However, his SSH in Windows 7 implementation seems to be a bit too extensive for my needs, so here's a bit simpler way of achieving pretty much the same thing.
  1. Download and install Cygwin. When installer lists packages to install, find openssh and rsync and check both for installation.
  2. Once Cygwin is installed, open Start menu, find Cygwin Terminal and run it as Administrator (right click -> Run as Administrator).
  3. Execute ssh-host-config in newly opened terminal.
  4. Answer Yes to privilege separation and new local account.
  5. Now, when asked whether to install ssh as a service, choose Yes - it will then prompt few other questions, e.g. to create new Administrator account in Windows etc.
    Note: Chris suggest a bit different way, tough - not installing openssh as a service and then running ssh daemon separately. See his implementation for details. I've personally tried both approaches and couldn't find any substantial difference (at least from my perspective), hence I chose to install as a service after all.
  6. (Optional) If you're planning to use ssh public key to login, execute:
    mkdir ~/.ssh
    > ~/.ssh/authorized_keys

    (note > at the beginning of the line above is actually legit)
Once openssh setup is concluded, we're ready to login from external host via ssh using Windows 7 user account username and password. 

However, if you're using password-less account in Windows, ssh daemon won't let you in. Again, there's detailed step-by-step explanation over at Chris' blog how to workaround this, however I chose simpler option - temporarily setup Windows account password, copy public ssh key using ssh-copy-id to sort out future ssh logins and then remove password from Windows account. Worked pretty well to me.

Finally, Cygwin offers pretty neat feature of accessing all Windows drives (including external ones!) at /cygdrive path. For example, hard drive/partition C: will be accessible at /cygdrive/c, D: at /cygdrive/d etc. Needless to say that setup makes my rsync backups to external USB drive a breeze.

1 comment:

  1. Great solution, Dawid. It'll be great if you post later on the same tip for Windows 8. Because as far as I've heard, laptop manufacturers agre going to use it heavily.