Fork me on GitHub
Web Development
This Website
message icon wishlist icon

Resources for web developers and other stuff™
12:44 12/07/2005

Cygwin as UNIX emulator


(A) Use Cygwin as UNIX environment on Windows for shell scripting.

(B) Run sshd as Windows service.

(C) Run crontab as Windows service.

(D) Use bind tools in Cygwin (host, dig)


The ability to write and test shell scripts on your home PC before running them on a remote host is very useful. Normally one would edit remotely via ssh with much lag. Local writing and testing on your Windows machine lets you work out the various parts of your scripts much more easily and quickly, without having to install or boot up into a UNIX operating system.

Access to UNIX tools like sed, grep, awk, crontab etc. is also very handy to have in Windows. You can even run sshd in cygwin and remotely connect to your Windows computer securely.

Method Part A

Note: I recommend you use bash as your interactive shell, even if you code shell scripts in ksh. Why? Bash on cygwin has tab-completion, arrow key history, colour term etc. already setup, and it's a bit of pain to do it in ksh.

Download the latest version of cygwin setup from

Choose "Install from Internet", and directories which suit you.

When at the "Select Packages" page add "rxvt" and whatever utilities you need, for example: vim, pdksh, openssh, cron, whois...

After installation open the installation directory and copy cgywin.bat something like login.bat

If you modify cygwin.bat directly it will be overwritten whenever you install new packages.

Modify login.bat; replace the line with "bash" to:

rxvt -fn FixedSys -sl 1000 -geometry 90x30 -sr -e bash -l

Here's a run-down of the above line:

Save login.bat and optionally change any links made by the setup program to point to login.bat

You're done! Check out your .bashrc and .bashprofile files and uncomment any useful aliases.

I added an alias to my .bashrc:

alias more='less'

So now you can launch login.bat and test our your shell scripts, before deploying them on the remote host.

Method Part B

Once you have installed the openssh packages you need to run

Home@paws ~
$ ssh-host-config

Specifying "CYGWIN=ntsec term" when asked.

Enter "yes" when the script will ask you whether to add sshd as a Windows service.

From then on you can remotely connect to your Windows computer, assuming you have opened port 22 (or whichever port you wish to run sshd on, configurable in /etc/sshd_config) in your firewall.

To start the service type:

Home@paws /etc
$ net start sshd

Method Part C

Once you have installed the cron package you need to run

Home@paws /etc
$ cygrunsrv -I cron -d "CYGWIN cron" -p /usr/sbin/cron -a -D

This will install a Windows Service with cron. Make sure /var/run/ is writeable by SYSTEM user (deleting it if it exists is one way)

To start the service type:

Home@paws /etc
$ net start cron

If you have any problems starting the services check the Windows Event Log, under Applications. You should be able to solve any issues from there.

Use the command "crontab -e" to edit your crontab, and don't forget "man 5 crontab"!

Method Part D

The ISC Bind tools are extremely useful for DNS related queries. Among them are "dig", "nslookup", "host".

As of writing a "native" cygwin version of Bind has not been packaged and made available through the setup program.

I had success with installing the Windows binary for ISC Bind and including the Bind binary path to the system PATH variable.

The Windows binary of Bind 9.3.1 can be found here.

Once installed, modify the system PATH (right-click on My Computer -> Properties -> Advanced -> Environment Variables) to include the "bin" directory of bind, and start the "ISC bind" service which should have been installed.

You should now be able to use "dig" etc.!

Home@paws ~
$ which host

Home@paws ~
$ host has address

Home@paws ~
Copyright © 2002-2017 message icon Amadeus Stevenson, Photo credit: Klaus Post
wishlist icon