PDA

View Full Version : Tutorial: Installing cygwin and openssh on Windows and setting up an OpenSSH server.



x88x
09-30-2010, 09:06 PM
This was requested, so here ya go. I hope it helps.

I did this on XP since that was the first VM I grabbed that actually had a snapshot without it installed, but these instructions should work the same on any version of Windows.


"Cygwin is a Linux-like environment for Windows"
This official statement of purpose sums it up pretty nicely. The upshot of this is that a lot of Linux CLI utilities can be fairly easily installed and used in Windows.

Installing cygwin is a bit more complicated than a normal program, but it's a lot more versatile as well. You see, the cygwin installer is more than just an installer. It is the package manager for all the applications available for the cygwin environment.


Note before install in case you normally install things to unusual places:
The default cygwin install, including the packages I add in this guide, come to a grand total of 135MB. So, unless you are severely lacking disk space, I would recommend installing this to the same drive as your OS.

To install cygwin (http://www.cygwin.com/):

1) Download the cygwin program (http://www.cygwin.com/setup.exe).

Because the program is the package manager and updater as well as the installer, you probably want to keep it around. The next step is optional and is just my personaly prefered way of doing this.

2) Run the program and advance to the 'Select Connection Type' screen, changing any options along the way. At this point the directory structure will be created (default is C:\cygwin). At this point, cancel the installation process, delete the setup log files that it created in the directory that the exe is currently in, and move the exe to the cygwin directory.
http://i428.photobucket.com/albums/qq3/x13931x/cyg00.png

3) Run the program again and continue through the install.

4) At the 'Choose Download Site(s)' screen, pick whichever mirror(s) you like. I've found that the xmission servers usually give really fast
connections, so I select those two.
http://i428.photobucket.com/albums/qq3/x13931x/cyg01.png

5) At the 'Select Packages' screen you begin to see the true function of this program, not simply as an installer, but as a package manager. You can browse packages using a number of different views (switchable using the 'View' button in the top right of the window). I prefer 'full' to 'category', as it makes it easier to find something I am specifically looking for. To select a package for install, click where it says 'skip' to select it for install.
http://i428.photobucket.com/albums/qq3/x13931x/cyg02.png
http://i428.photobucket.com/albums/qq3/x13931x/cyg03.png

6) You will want to select the following packages to create an OpenSSH server:
binutils
openssh

I would also recommend installing a CLI text editor, just on general principles. I prefer nano, but many others are available including vim and emacs.

Dependencies are resolved automatically at the next screen.
http://i428.photobucket.com/albums/qq3/x13931x/cyg04.png

7) Wait for the packages to be downloaded and installed. This may take quite a while depending on your internet connection speed. Go get a sandwich or something.

8) The last thing you have to do in the cygwin installer is select where you want shortcuts. This is fairly straightforward and normal, but I feel I should point something out. The shortcuts that cygwin creates open a custom shell that is a bit more Linux-like than normal Windows CLI (tab-completion works correctly, a lot of the familiar hotkeys work, etc). This can be launched manually by running the 'cygwin.bat' file in the cygwin directory (in fact, this is what the shortcut does), but I have found that if I try and 'pin' the shortcut in Windows 7 it just launches the normal Windows CLI. XP appears to not have this bug for adding the shortcut the quick-launch list and it might have been fixed since I installed (I haven't actually updated it on my system for months).

We're almost done. The next few steps are not strictly necessary, but I like to do them to make for a more seamless experience, allowing you to use cygwin utilities from the normal Windows CLI in addition to through the cygwin shell.

9) Open 'System Properties' (right-click 'My Computer' and select 'Properties').

10) Select the 'Advanced' tab.

11) Select the 'Environment Variables' tab.

12) Select the 'Path' variable and select the 'Edit' button.

13) In the 'Variable value' field, add ";C:\cygwin\bin" to the end (minus the quotes). If you installed in a different directory, of course change "C:\cygwin" to whatever you used instead.
http://i428.photobucket.com/albums/qq3/x13931x/cyg06.png

14) Select 'Ok' in all windows.



Now all the software is installed, we just need to set up the SSH server.



To configure the OpenSSH server:

1) Open a cygwin shell.

2) Run:

ssh-host-config

-Unless you specifically know you want them to be something different, answer 'yes' to all questions.

-When it asks: "Do you want to install sshd as a service?", if you answer yes then it will start sshd on boot every time. If you answer no, you can always start it manually.

-If it asks "Enter the value of CYGWIN for the daemon", you can leave that blank and just hit enter/return/whateveryourliketocallit.

http://i428.photobucket.com/albums/qq3/x13931x/cyg05.png

-The config script tells you this at the end, but to reiterate, the ssh server can be started using either of these commands, or, if you chose to install sshd as a service, it will also start on the next reboot.

net start sshd
cygrunsrv -S sshd

From here you can do any configuration that you want as you would on any Linux system.



A couple notes:
-In the cygwin shell, "/" is the cygwin install directory ("C:\cygwin" in my case), and any system drives can be accessed in the "/cygdrive/" directory.

-User accounts and passwords are stored by cygwin separately from Windows, but are copied over the first time you open a cygwin shell. They can also be copied over at any point in the future using the command below. NOTE: This will overwrite any changes you have made to cygwin user accounts and passwords.

mkpasswd -l > /etc/passwd

So, as the ssh config said, Have fun! If you have any questions or I didn't explain something well enough, just ask. :D

Trace
09-30-2010, 10:34 PM
Thanks! I'm trying it now!

[edit] SEEMS TO BE WORKING!!!!

x88x
09-30-2010, 10:49 PM
One thing I forgot until just now...I think if you do not have a password set for an account it might get confused when you try to SSH in...or that might have been Ubuntu... :think:

Trace
10-01-2010, 10:54 PM
How do i make an account interactive.

x88x
10-02-2010, 12:15 AM
Sorry, I'm not getting your meaning. :?

Trace
10-04-2010, 06:55 PM
The Putty window closes immediately upon login. It seems I need an "Interactive User" so my window doesn't close.

x88x
10-04-2010, 07:58 PM
Well, according to Microsoft (http://msdn.microsoft.com/en-us/library/ms686587%28VS.85%29.aspx), an interactive user is just a user that's logged in on the system that a COM server is running; ie, the computer running cygwin in this case, which you're obviously going to be if you can actually run it..hmmm... Is this in Vista or 7? If so, try going to the cygwin directory and running the batch file directly as an administrator. It might not have the permissions as a normal user to access the account/etc files that it needs for the initial setup.