Tuesday, February 07, 2006

PuTTY command line

PuTTY is my favorite SSH Client. However its configuration is somewhat cumbersome. Using a little batch file allows me to apply a set of default settings to any host I like.

Where I work we have a lot of Linux based clients around the world that function mostly without any manual intervention on behalf of an administrator. However there are times of course, when we still need to access one of those systems. Unfortunately there are literally hundreds of them, and anybody who has used PuTTY before knows that it is not fun to create a session entry for each and every one, including port forwarding options, private key file etc. Of course, one might say you could just export the Registry key for a single session and use that as a template and reimport it into the registry. However this is a single-shot approach, because after the copy has been made, you cannot globally change a setting, say the path of the private key file you want to use. Furthermore you may not be allowed to edit the registry on any given system.

While looking for a solution and examing the PuTTY command line options I found that you can easily mix all command line options (e. g. tunnel options, key file name etc.) with a "-load" option. This allows you to define a "template" session via the PuTTY GUI that includes everything you need to configure but cannot specify on the command line (e. g. the character translation). So in the end I came up with a simple Windows batch file that has the follwing content:

echo Hostname:
set /p hst=
putty.exe -C -2 -4 -i ".\keyfile.ppk" -L 5999:127.0.0.1:5901 -l username -ssh -load "Template Session" %hst%

This lets me first enter the hostname or IP address of the host I want to connect to and then opens a session that is based on the configured settings in "Template Session" and completed with the options -C (compression), -2 (SSH2), -4 (IPv4), -i (which keyfile to use), -L (tunnel specification), -l (the remote username), -ssh (SSH protocol) and finally the hostname I just entered.

This has made my life a lot easier, because with this I can finally connect to any box I like while still having the flexibility of a global set of preferences that can be changed easily. Of course, some of the options are not strictly neccessary (like the -4 option), but they do no harm either.

1 comment:

Anonymous said...

Perfect. thx