Sep 08

1. Download cygwin from http://cygwin.com/. Run the setup program and select the packages you want. The simplest thing to do is to get the default packages that are selected for you by the installer, plus “cygrunsrv” from the admin category and “openssh” from the net category. I found installing cygwin to be the easiest part of the process, and if you get stuck there’s lot’s of great help out there…

2. Edit C:cygwincygwin.bat. Make sure it contains the following setting for the CYGWIN environmental variable:

set CYGWIN=binmode tty ntsec

2. Start a cygwin bash shell. If cygwin installed correctly, you should be able to find it in start->programs->cygwin.

3. Make sure cygrunsrv is installed by typing “cygrunsrv -S sshd”. This is the command that will start the sshd server, but that’s not installed yet. If you get an error from cygrunsrv like “service does not exist” then you’re on the right track. If you get “command cygrunsrv not found” then go back over your install and make sure you get cygrunsrv.

4. Again from the bash shell, run ssh-host-config. Answer yes to the key generation questions. I found it easier not to use privilege separation. Answer yes to install as a service.

5. Start sshd with “cygrunsrv -S sshd” (“cygrunsrv -E sshd” shuts it down). At this point you should also have “Cygwin sshd” available as a service that you can start and stop from start->control panel->administrative tools->computer management – go to the services and applications->services list.

6. If all that went well, you should be able to ssh to the server(“ssh localhost -l loginName”). At this point only user accounts that existed before your cygwin install and had administrator access will work. This and the next step were the biggest gotchas for me in this whole game.

7. To enable a user to log in via ssh: You should know that sshd looks for information in the comments field of /etc/passwd and coordinates it with NT permissions. This was mentioned but not explained in the howtos I read.

Here’s how make it work: First, create the NT user and make them part of the administrators group.

Next, use the mkpasswd command to format a special passwd entry for that user. You can look at the output with the command “mkpasswd -l”. Then either cut and paste the info you need into your /etc/passwd file, or use the command “mkpasswd -l > /etc/passwd”.

This second will overwrite your existing passwd file. No matter what you do, make a copy of /etc/passwd before making any changes.

Create home directories for your users with the following commands:
“mkdir /home/userLogin”
“chown userLogin /home/userLogin”

Sshd only reads /etc/passwd once when it starts, so stop and start the server after you make changes to /etc/passwd.

I take it the mkgroup command does the same thing for /etc/group as mkpasswd does for /etc/passwd; I never needed to use it.

written by MG \\ tags: ,

3 Pings to “How to configure cygwin for sshd”

  1. Tweets that mention How to configure cygwin for sshd » MG's Notes -- Topsy.com Says:

    […] This post was mentioned on Twitter by bunny_car. bunny_car said: http://tinyurl.com/26h7rcp How to configure cygwin for sshd pt access fara parola (MUGUREL.SUMANARIU.RO) […]

  2. fstyle.de » Blog Archive » How to configure cygwin for sshd Says:

    […] was needed to setup the ssh server for cygwin (http://mugurel.sumanariu.ro/windows/how-to-configure-cygwin-for-sshd/): 1. Download cygwin from http://cygwin.com/. Run the setup program and select the packages you […]

  3. How to generate RSA keys for Cygwin and Ubuntu - How To Tech Tutorials Says:

    […] Special thanks to these sites, please visit: http://chinese-watercolor.com/LRP/printsrv/cygwin-sshd.html http://mugurel.sumanariu.ro/windows/how-to-configure-cygwin-for-sshd/ […]


6 Responses to “How to configure cygwin for sshd”

  1. 1. Sada Says:

    Nice article.

  2. 2. Stefan Denchev Says:

    And what if i don’t want everyone who uses ssh to have administrative privileges?

  3. 3. jk Says:

    to append to the password file, rather than replace the password file: use the command “mkpasswd -l -u “username” >> /etc/passwd”
    1 x “>” replaces the file && 2 x “>>” appends to the file

  4. 4. vish srinivasa Says:

    Thanks for clearing some of the points already covered under http://docs.oracle.com/cd/E24628_01/install.121/e22624/preinstall_req_cygwin_ssh.htm#EMBSC281. However I have been racking my brains on this setup for a week now with a constant error stating ‘Connection closed by <IP.. Couldn't read packet: Connection reset by peer.

    I have followed the instructions to a T and done multiple re-installs but it still does not work. What am I doing wrong? Please help!!

  5. 5. Ashish Says:

    I want to install SS server on win-7. I installed the cygwin but not able to do ssh from either window or linux m/c . I think my configuration are not complete.
    I configured the ssh service as well.
    Please tell me the username from my mkpasswd -l ;

    $ mkpasswd -l

    T430+cygwin_server:*:197614:197121:U-T430\cygwin_server,S-1-5-21-1537817257-3777222404-1114005467-1006:/home/cygwin_server:/bin/bash

    and How to create the NT user and make them part of admin group. Could you please share the commands or screen-shots.?

    Thanks,
    Ashish

  6. 6. dvl Says:

    the idea that you should default to putting ssh users in the Administrators group is absurd and dangerous. What if an assailant scans for your port 22, finds sshd listening, guesses someone’s crappy insecure password, and gets root on your local machine?

    I remove such people even from Users – and make sure they have no local login/browse privileges, _only_ remote connection and working within their alloted directories.

    Please, try harder

Leave a Reply

*