Launch putty from browser
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?
- Register a new protocol (in our case, let’s call it “ssh”) to Windows’s registry.
- Create a batch file that can take in strings such as “ssh://google.com” and massage them and pass them on to putty.exe
- 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.