an introduction to openssh part 4 — SSH on Windows

It is ideal if we can live in a Unix only world. However sometimes we’ll need MS windows. In this part we’ll talk about using OpenSSH, or SSH in general, on MS Windows platform. On the OpenSSH Alternatives for Windows page, there is a list of available free/open source software. We’ll talk about the two most commonly used solution: OpenSSH on Windows, and PuTTY.

- OpenSSH on Windows.

To run OpenSSH on Windows, we’ll need the Cygwin package. Cygwin is a Linux-like environment for Windows. It was first started by a group of geek who are familiar with the Unix environment, and was forced to move to Windows.

There are two part of Cygwin, a DLL to semulate the POSIX environment on windows, and a set of tools that runs on this DLL. Cygwin did a pretty good work so most of the command line tools and a lot of GUI tools are supported. And for sure OpenSSH is in the
list.

To install Cygwin you’ll first need to download a boot tramp setup.exe, and run it as any other setup.exe on Windows. It will ask you a few questions, like choosing the mirror site, and then allow you to choose which package to install.

After installation you can click “start” -> “program” -> “cygwin” -> “bash prompt”, and a command line windows will show up. In this window the “ssh” command is available, as long as you choose to install it in the step above. There is no difference when using it under Cygwin/Windows than using “ssh” command on Linux. All the tips we talked in the privious parts works. Anyway, they are the same source code, just compiled to run on different platforms.

The good thing of using OpenSSH on windows is that you are 100% compitable with OpenSSH on Linux. The bad thing is, well, first, it is kind of wired to use a command line tool on Windows, and second, you’ll need the Cygwin package to use it.

- PuTTY and friends.

PuTTY is a free telnet and ssh client. It can run on both win32 platform and on Unix-like platform. It is a collection of tools.

The most import one is, of cause, putty.exe. It is a combination of a ssh client and an XTerm emulator. It is used for interactive SSH sessions. It comes with ANSI color support, different key emulators, etc, and much better than the MS Windows command line. When started
it will show a configuration dialog, and you can just click around to turn it fit your needs. If you are not satisfied, there is pietty, which is a modified version of putty which support some neat features like URL recognition, semi-transparent, drag and drop, etc. And most important, for non-English users, it comes with full Unicode font, so you can use it to access non-English stuff on an English windows (or a Windows doesn’t support the character set on
your Unix machine).

The 2nd most commonly used one is pagent.exe, if you are using SSH2 key based authorization. It is the Putty version of ssh-agent. You can see a computer with a hat in the system tray if pagent is running. It is a command line tool. If you don’t like to start the
MS command line window and switch to the right directory every time, you can use a .bat file like this:

@echo off

set PAGENT_PATH="putty\PAGEANT.EXE"
set PRIVATE_KEY_FILE="putty\pkey.ppk"

rem ### launch pagent
%PAGENT_PATH% %PRIVATE_KEY_FILE%

Note you’ll need to modify the first two parameters first to fit your environment.

Talking about key based authorization, another tool puttygen.exe is used to generate the key pair. It comes with a GUI interface and is pretty easy to use. One note is that the format of the key recognized by Putty is different than the key generated by OpenSSH. So if you have a key already on Linux and want to use it on MS windows with Putty, or you generated a Putty key pair and want to put the public key on to the server, be sure to use the import/export key function in the “Conversations” menu. Many people faild to logon to the server via SSH2 because they put the Putty generated public key file directly on to the server, and the OpenSSH
on the server can’t recognize it.

Pscp.exe and Psftp.exe are the Putty equivalent of “scp” and “sftp”. However if you are using Windows you might want a GUI interface instead of these command line one. FileZilla is a good candidate. And the good thing is, pagent.exe and FileZilla can work together so as long as you hvae pagent.exe running and holding your key, you won’t need to input it again in FileZilla.

Last, but not least, is the plink.exe tool. It could be used as a “transporter”. That is, many programs, especially those ported from Unix platform, will call the ssh command, through a pipeline or a command option. This is common on Unix. Because the Putty.exe is a
graphic tool and can’t be used in this environment, plink.exe is provided. It is really for experts only :)

Putty is so widely used that it is ported to various platform. Check the Putty Links page out, especially if you have a recent hand held running Windows Mobile, Symbian, or Palm and you want to connect to your server on the road.

Another way to connect to your server when you are not infront of your desktop is to put Putty in a USB key. However Putty is not a portable program: it write your settings to the registry. So if you are on someone elses’ machine you won’t have the record and config
you usually use.

One way to solve this is to use PuttyConfer. It is a GUI program that you can import/export Putty settings, among other things. So you can export all your settings to your USB key with PuttyConfer, and import it when you needed on another machine.

Another way is to use some *.bat scripts. The following is what is on my USB key now. I got it on the Internet a long time ago and modified it a little bit. Fell free to modify it to suit your needs.

file start.bat:

@ECHO OFF
regedit /s putty.reg  

file end.bat:

regedit /ea new.reg HKEY_CURRENT_USER\Software\SimonTatham\PuTTY
copy new.reg putty.reg
del new.reg
regedit /s puttydel.reg  

file puttydel.reg:

REGEDIT4
[-HKEY_CURRENT_USER\Software\SimonTatham\PuTTY]

You can put these three files into the same directory. The last line of end.bat and the file puttydel.reg is to remove the Putty settings from Windows registry. If you want to keep them, you can safely comment the last line of end.bat off. To use, you need to run end.bat first on your desktop, where you normally run putty. This will generate a file named “putty.reg”. This file holds all your settings. When you get to a new machine, you can use the “start.bat”
script to import your settings, and then start Putty.exe.

There are other programs support SSH on windows, some commercial, some free. But hey, with the good and free Linux, who would gonna use M$ Windows? :)

Tags: , , , , , ,

Comments 1

  1. Andre wrote:

    I’m using AutoHotkey now to start Putty and Plink. It can also set Internet Explorer’s proxy setting to an open Plink. Press the hotkey, choose the host, and you’re connected. Much simpler.
    Feel free to contact me by e-mail if you would like to help me make it releasable.

    Posted 18 Dec 2008 at 5:35 am

Post a Comment

You could use <code type="name"> to get your code colorized

Your email is never published nor shared. Required fields are marked *

Close
E-mail It