Launch putty from browser

Posted on May 12, 2009. Filed under: Linux, Windows |

Launch PuTTY from Your Browser – Adding Procotols to Windows

For awhile now, I have wanted the ability to launch putty from a simple hyperlink.

PuTTY enables Windows users to access *nix machines through SSH. For many in the tech industry this tool is absolutely crucial. While it is fairly full featured, it is quite cumbersome for generic SSH use. One may say “Jon, all you need to do is run PuTTY, enter the host name you wish to connect to and provide a user name and password.” This process is certainly fine for a single SSH operation. This becomes quite a pain with multiple hosts at once.

What if there was a way to create a hyperlink which launches PuTTY? One would be able to launch PuTTY from email clients, browsers, spreadsheets, etc…
An example link would be: ssh://google.com

What do we need to do?

  1. Register a new protocol (in our case, let’s call it “ssh”) to Windows’s registry.
  2. Create a batch file that can take in strings such as “ssh://google.com” and massage them and pass them on to putty.exe
  3. Point the registry modification to that batch file.

One method of editing the registry is to create a .reg file, save it, right click it and select merge. The .reg file will then be merged with the registry. We will use this method. The key created can always be deleted by later from regedit.

Here is an example .reg file which points the protocol “ssh” to a batch file located at “C:/putty_util.bat” :

REGEDIT4
[HKEY_CLASSES_ROOT\ssh]
@="URL:ssh Protocol"
"URL Protocol"=""
[HKEY_CLASSES_ROOT\ssh\shell]
[HKEY_CLASSES_ROOT\ssh\shell\open]
[HKEY_CLASSES_ROOT\ssh\shell\open\command]
@="\"C:\\putty_util.bat\" %1"

Now save ssh.reg locally, right click it, and select merge.

Note: You can create any new protocol by changing each “ssh” in this .reg file to whatever abbreviation you wish to use for your protocol. You will likewise want to change the string @=”\”C:\\putty_util.bat\” %1″ to point at whatever application you wish to use. In this case, we are using the application C:\putty_util.bat and passing in the first argument we receive to it. In the example of ssh://google.com, we will be passing in the string “ssh://google.com”

Unfortunately, PuTTY does not understand arguments which start off with “ssh://” . As a result, we must use a batch file (C:\putty_util.bat) to remove the “ssh://” and any other oddities. Here is the batch file for my box:

@echo off
set var=%1
set extract=%var:~6,-1%
"C:\Program Files\PuTTY\putty.exe" %extract%

set extract=%var:~6,-1% is telling us to remove the first 6 characters and the last character from var and place that value in extract. The removal of the first 6 characters is the removal of “ssh://”. We remove the last character as there seems to be a trailing slash present in the input to our batch file.

With extract holding just the hostname, we now execute putty.exe and pass in extract as an argument. In this case, putty.exe is located at C:\Program Files\PuTTY\putty.exe. Please change this to the location of your putty.exe. Save this batch file to C:\putty_util.bat

Once this is done, anytime you have a link such as ssh://google.com you should be able to simply click it and launch PuTTY.

I will have a followup post with instructions on how to accomplish the same with ssh in other operating systems.

Sources:

http://kb.mozillazine.org/Register_protocol

External Links:

http://www.putty.org/

 

References:

http://jonmicklos.com/blog/?p=77

http://kb.mozillazine.org/Register_protocol

http://msdn.microsoft.com/en-us/library/aa767914(VS.85).aspx

http://www.chiark.greenend.org.uk/~sgtatham/putty/wishlist/url-launching.html

http://forums.whirlpool.net.au/forum-replies.cfm?t=326109

http://forums.cacti.net/about22862.html

About these ads

Make a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

6 Responses to “Launch putty from browser”

RSS Feed for John's Blog Comments RSS Feed

Great post !

Works like a charm and really solved my problem .

Thank you very much..

I tried to use the instructions but the cmd.exe is alive after the putty launch. so I modified the code in putty_util.bat

@echo off
set var=%1
set extract=%var:~6,-1%
CD C:\Program Files\PuTTY
start putty.exe %extract%
exit

Thanks – works perfectly on Win2k8 x64 SP2… I use this to launch SSH and RDP sessions from a shortcuts page…

With the BAT above, the CMD window will stay open while the PuTTY/app stays open. Instead, change the command that launches PuTTY to use the START command, which will launch PuTTY in a new process, and allow the CMD window to close.

START “” “C:\Program Files (x86)\PuTTY\putty.exe” %extract%

This is really useful information. Just the stuff I was looking for. THANK YOU!

Thank you very much

Very cool, but how is this done for telnet ???? instead of SSH ??? – and also, how can you map the URL to a saved session in putty (i.e. with custom parameters for logging, window appearance and scroll back, etc.)?


Where's The Comment Form?

Liked it here?
Why not try sites on the blogroll...

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: