Make ssh:// links open with PuTTY

15

6

Is there a way to associate hyperlinks on websites that are in the format ssh://10.10.10.10 automatically open and connect using PuTTY?

I'm looking for a solution that will work cross-browser (IE and Firefox) and is easy to implement. I can't give instructions to our support team to perform registry edits manually :(

Anyone know how to make that work?

Mistiry

Posted 2010-10-27T20:42:06.293

Reputation: 4 759

Answers

8

There is a Putty fork named Kitty, it's website includes instructions for doing exactly what you want.

It does involve registry changes but these are accomplished by downloading a .reg file and clicking on it in windows explorer (with admin privileges I guess).

RedGrittyBrick

Posted 2010-10-27T20:42:06.293

Reputation: 70 632

5

PuTTY unfortunately does not associate itself with the ssh:// URLs.

You can associate an application with a protocol manually. See the MSDN article Registering an Application to a URI Scheme.

Basically you add a registry key like:

[HKEY_CLASSES_ROOT\ssh]
@="URL: SSH Protocol"
"URL Protocol"=""

[HKEY_CLASSES_ROOT\ssh\DefaultIcon]
@="\"C:\\Program Files (x86)\\PuTTY\\PuTTY.exe\",0"

[HKEY_CLASSES_ROOT\ssh\shell]

[HKEY_CLASSES_ROOT\ssh\shell\open]

[HKEY_CLASSES_ROOT\ssh\shell\open\command]
@="\"C:\\Program Files (x86)\\PuTTY\\PuTTY.exe\""

Though the above passes a whole URL to the PuTTY command-line. And PuTTY does not understand the ssh:// prefix. So you would have to add a wrapper script that strips the ssh:// and passes only a user and a host to PuTTY.

For that see:
https://johnsofteng.wordpress.com/2009/05/12/launch-putty-from-browser/


Another way is using WinSCP. It registers itself to handle the ssh:// URL and opens the session specified by the URL in PuTTY.

(I'm the author of WinSCP)

Martin Prikryl

Posted 2010-10-27T20:42:06.293

Reputation: 13 764

2

Here's a registry class that'll remove the ssh:// and trailing (actually, all) / from the URI before passing it to PuTTY so PuTTY can directly open it:

Per User:

Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Classes\ssh]
@="URL:ssh Protocol"
"URL Protocol"="ssh://"
[HKEY_CURRENT_USER\Software\Classes\ssh\shell]
[HKEY_CURRENT_USER\Software\Classes\ssh\shell\open]
[HKEY_CURRENT_USER\Software\Classes\ssh\shell\open\command]
@="cmd /V:ON /c set params=%1 && set params=!params:ssh://=! && start \"PuTTY\" \"c:\\Program Files (x86)\\PuTTY\\putty.exe\" \"!params:/=!\""

And, for everyone on the system:

Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\ssh]
@="URL:ssh Protocol"
"URL Protocol"="ssh://"
[HKEY_CLASSES_ROOT\ssh\shell]
[HKEY_CLASSES_ROOT\ssh\shell\open]
[HKEY_CLASSES_ROOT\ssh\shell\open\command]
@="cmd /V:ON /c set params=%1 && set params=!params:ssh://=! && start \"PuTTY\" \"c:\\Program Files (x86)\\PuTTY\\putty.exe\" \"!params:/=!\""

Change the file path based off of your needs.

/V:ON is the same as 'SetLocal EnableDelayedExpansion'

/c runs the command

I set params to the paramater which is 'ssh://domain.tld/'. Then I strip the 'ssh://' from it with the '!params:ssh://=!', which is a find-replace for 'ssh://' to '' on the variable params. I assign that back to params, now params = 'domain.tld/'. I then pass it to putty and do another find-replace to replace '/' with '' to remove the trailing slash that Windows puts on, leaving 'domain.tld' which PuTTY can use.

This lets me process it all in the command entered in the registry entry. It doesn't do any sort of sanitizing at all and is easily exploitable (Ex. ssh://&&notepad opens notepad) so you might want to change the URI to something only you know.

Nathan Ladwig

Posted 2010-10-27T20:42:06.293

Reputation: 111

2

See this: https://gist.github.com/sbiffi/11256316

I wanted a solution which does not need to change putty.

It associates a visual basic script to ssh:// and telnet:// URLs, which parses the URL and launches putty using standard parameters like putty.exe -ssh -l login.

2 additional advantages: – Password can be passed in URL also for auto authentication – No need to change putty, thus adapted to all patches.

user3568910

Posted 2010-10-27T20:42:06.293

Reputation: 21

2

I figured out a way to do it with just registry keys using a PowerShell command. Here you go.

– ubomb – 2015-04-09T21:42:44.587

@ubomb FYI, there's an answer from 2017 that looks similar to the cmd.exe version in your question. Perhaps it's different enough to overcome the limitations you faced before switching to PowerShell.

– jpaugh – 2019-08-07T19:43:06.187