Hack 96 OpenSSH on Windows Using Cygwin

figs/beginner.giffigs/hack96.gif

Use any of the powerful OpenSSH hacks in this chapter on a Windows box.

So you've read all the nifty cool hacks so far using OpenSSH, but you're a Windows guy or gal who hasn't (yet) taken the plunge into the world of Linux. That's okay! You can still take advantage of the power of OpenSSH on your Windows box by using a tool called Cygwin.

As the Cygwin web site explains:

Cygwin is a Linux-like environment for Windows. It consists of two parts:

A DLL (cygwin1.dll) which acts as a Linux emulation layer providing substantial Linux API functionality.

A collection of tools, which provide Linux look and feel.

This powerful and free package allows you to run many free software packages in Linux, all without leaving the safety and comfort of your Windows environment.

Installation

The software can be downloaded from http://www.cygwin.com/. To install Cygwin, run setup.exe and then select the Linux tools you want to install. These will be downloaded from the Internet and installed automatically. Using setup.exe, you can also choose to download only the install files, or to install them from a local directory. For the purposes of this hack, I assume that you are installing directly from the Internet.

In the first dialog box, choose an installation directory, installation type, and default text file type. Unless you need to change any of these options, just stick with the defaults for now. In the second dialog box, choose a directory where the software packages will be downloaded. This is useful to remember if you're going to be doing multiple installs. Third, you need to choose an Internet connection type. If you're inside a corporate network, you may need to consult with someone on these settings. Generally a direct connection works if you are a home user.

Lastly, you need to choose a download site. There are a whole range of sites listed, located all around the world. Choose the site that is roughly closest to your country.

setup.exe will then download the next portion of the setup program, and you will be prompted to Select Packages, as shown in Figure 7-9.

Figure 7-9. Cygwin Install Packages screen.
figs/wh_0709.gif

There are a large number of software packages that Cygwin can install for you. To add OpenSSH as an installed software package, navigate to the Net category. Click on the plus sign next to Net and scroll down until you find the line that lists OpenSSH, as shown in Figure 7-10.

Figure 7-10. Locate openssh.
figs/wh_0710.gif

Click once on the word "Skip" on the line that shows openssh. You will see the change shown in Figure 7-11.

Figure 7-11. Select openssh.
figs/wh_0711.gif

Note that when you selected openssh, openssl is also automatically selected. This is because openssh relies on the encryption routines contained in openssl.

One more package you will need to install, particularly if you want the sshd daemon to run as a service in Windows 2000 or Windows XP, is cygrunsrv. This package can be found in the Admin category, as shown in Figure 7-12.

Figure 7-12. Select cygrunsrv
figs/wh_0712.gif

Click Next, and Cygwin will begin downloading and installing the selected packages. Once installation is done, you'll have Cygwin icons on your desktop and in the Start menu.

To get things properly set up, you need to change a few things in your System Environment. In Windows 2000 and Windows XP, right-click on My Computer and choose Properties. Click on the Advanced tab and then select Environment Variables. Find the variable for Path and double-click on it. At the end of the path, add a semicolon and the full path to the installed Cygwin (C:\cygwin\bin by default, unless you changed it when you installed it). Also add a new variable by clicking on New. The variable name is CYGWIN. The variable value should be ntsec tty.

OpenSSH Configuration

To get the openssh daemon running, open up a Cygwin bash shell and run this:

Administrator@notebook ~$ ssh-host-config -y

This generates ssh keys and an sshd config file for your system, and sets up sshd to run as a Windows service. You'll be prompted for a value of CYGWIN for sshd at startup. Enter the same string that you used for the CYGWIN environment variable: ntsec tty.

Now you can start up sshd as a service by running this command:

Administrator@notebook ~$ cygrunsrv -S sshd 

You can test your sshd installation by typing ssh localhost. If all goes well, you should be able to log in to your own machine.

You should now be able to copy files with scp, set up key dependencies, and use all of the other time saving SSH tips and tricks mentioned elsewhere in this chapter. For example, you can secure your email by using port forwarding [Hack #93]. With sshd up and running, you can even connect to your Windows machine from other computers running ssh. Cygwin might not be quite as powerful as a complete Linux installation, but it allows you to use many important free software packages without even having to reboot.



Wireless Hacks. 100 Industrial-Strength Tips and Techniques
Wireless Hacks. 100 Industrial-Strength Tips and Techniques
ISBN: N/A
EAN: N/A
Year: 2003
Pages: 158

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net