Open ssh URLs in chrome and firefox

If you are using some simple web applications that provides list of devices that you can connect using ssh it is useful to auto launch terminal with ssh connection started.

I am doing this on debian 9.5, chromium 69.0 and firefox 60.3.

First we need to setup xdg-open to handle ssh URLs. Create script that will start terminal together with ssh command:


cat /home/zzorica/scripts/ssh-handler.sh
#!/bin/bash

d=${1#ssh://}
#gnome-terminal -e "ssh $d" &
terminator -e "ssh $d" &

To test you can run ./ssh-hander.sh ssh://user@192.168.1.1 and it will launch another terminal (terminator in this case, or you can adjust for some other) with ssh connection open. You can put this script wherever you like. Next create desktop launcher so you can link it with xdg-open. Just make sure the path to previous script is correct.


cat ~/.local/share/applications/ssh-handler.desktop
[Desktop Entry]
Type=Application
Name=SSH Handler
Exec=/home/zzorica/scripts/ssh-handler.sh %u
Icon=utilities-terminal
StartupNotify=false
MimeType=x-scheme-handler/ssh

Now we need to make sure that ssh URL are opened with this launcher. To do that put handler into your mimeapps.list. If you don't have this file create it. Default location is the same where you created .desktop file.


cat ~/.local/share/applications/mimeapps.list 

[Default Applications]
text/html=chromium.desktop
x-scheme-handler/http=chromium.desktop
x-scheme-handler/https=chromium.desktop
x-scheme-handler/about=chromium.desktop
x-scheme-handler/unknown=chromium.desktop
x-scheme-handler/ssh=ssh-handler.desktop

For test create simple html file and open it in both chromium and firefox. In ~/index.html put:


<a href="ssh://admin@10.1.0.2">LINK</a>

If you click on link in Firefox you will choose SSH Handler for default application:

In chromium just select xdg-open:

That's it. Now whenever you have ssh link in your browser it will open terminal window and start ssh connection. In case of the link above it looks like this: