Create a handler for opening special URLs like 'ssh://'

Jan 11, 2024 by Thibault Debatty | 326 views

Linux Sysadmin

https://cylab.be/blog/318/create-a-handler-for-opening-special-urls-like-ssh

Sometimes when using a web application you may encounter a special URL that does not start with http or https, like ssh://192.168.0.123 for example. On a mobile device, your phone will usually open the appropriate application to handle this URL. Here is how to achieve the same on a Linux computer.

.desktop file

  1. Create a .desktop file in /usr/share/applications/, for example /usr/share/applications/ssh.desktop , with the following content:
[Desktop Entry]
Version=1.0
Type=Application
Name=Open SSH URL
Comment=Open ssh://... URL
Terminal=true
Exec=gnome-terminal -- ssh %u
Icon=utilities-terminal
MimeType=x-scheme-handler/ssh;

Most lines are self-explanatory. The two import lines are:

  • Exec=gnome-terminal -- ssh %u that shows the command to execute. In this example we open a terminal to execute ssh, and %u is the actual URL. Other parameters can be found on the desktop entry reference page
  • MimeType=x-scheme-handler/ssh; that states that this entry should be used (executed) to handle ssh:// URLs
  1. The .desktop file must executable:
sudo chmod +x ~/usr/share/applications/ssh.desktop
  1. Finally, you must update the desktop entries cache:
sudo update-desktop-database

Test

If you have an SSH server installed on your machine, you can now test your handler with a link like this one:

ssh://127.0.0.1

SSH-URL-opener.png

This blog post is licensed under CC BY-SA 4.0

This website uses cookies. More information about the use of cookies is available in the cookies policy.
Accept