Saturday, April 4, 2009

Configure Cygwin and SSH on Windows

I was a dedicated Windows user for years but the more I get to know the Unix environment the more I like it. Cygwin provides a way to add some of the features of Unix, most specifically the command line, into Windows. Installing Cygwin by itself will give you a Unix shell within Windows, but you can also install a large number of packages along with to gain even more functionality. For my typical Cygwin install, the only extra I like to add is an SSH server.

The first step is to download and run the setup.exe file from the Cygwin website. During installation there are a couple of things to keep in mind. First, the default install location is "C:\cygwin". Like Unix, Cygwin doesn't like spaces in directory names, so the standard "Program Files" isn't a possible install location. The default location really should be fine.

Second, Cygwin gives you the option of going with "Unix/binary" file encodings or "DOS/text". The default and recommanded choice is the "Unix/binary". The only problem with that is that Notepad has trouble reading these types of files. I try to avoid using Notepad whenever possible and the much better Notepad++ will read these files beautifully. Notepad++ became my text editor of choice when I first discovered it a few years ago and I have yet to find anything I like as much for any platform.

The next thing you'll need to attend to is the packages to install. For the base install, you can skip right past this. If you want to install the SSH server, scroll down to the "Net" category. Expand it and scroll down and select "openssh". When you do this "openssl" will get selected automatically. Now finish the installation and you should have a Cygwin shortcut on the desktop.

Launch Cygwin and you will see a Unix shell. To set up the SSH server, there are a few more steps to follow. Enter these commands:
chmod +r /etc/passwd
chmod +r /etc/group
chmod 755 /var
Somewhere is the course of the Cygwin development a bug was created that caused problems with openssh and the default file permissions. These three commands fix that issue. Next enter this command to start the SSH server setup:
Answer "yes" to the next three questions. When you see the prompt: "Enter the value of CYGWIN for the daemon: [ntsec]" you should enter "ntsec". Okay, configuration is done. To start the service, type:
net start sshd
Now you should have a working SSH server on your Windows machine along with a working Unix command line environment. Depending upon what you use for a firewall, you may need to open a port in order to access the SSH server. SSH by default uses TCP port 22.

If you want to install any additional packages, just run through the installer again and select whichever additional packages you want and it will install them for you. For more information on how to use CYGWIN, Lifehacker has a three part tutorial to check out:
Part 1
Part 2
Part 3


  1. If you've started using linux, check out nedit as an alternative to notepad++.

    It works in much the same way, but it conveniently lets you filter whatever text you've selected though a pipeline of bash commands, which is wonderfully useful.

  2. vi, vim, emacs. Great editors with unsurpassed options, commands, and text search and replacement with regex! Just keeping all the commands and short-cuts in your head is hard, but that is what cheatsheets are for. What other (light) editor allows you to select and copy a column of text to copy, cut, or run some command on. They don't look like much, but that's because they do so much.

  3. ViM all the way!

  4. My AFS mounted drives are not showing up in the /cygdrive directory. Why?


Note: Only a member of this blog may post a comment.