4

I found a nice way to open a terminal with SSH to user@host if you click on a link that looks like this:

ssh://user@host

I guess the above solution works. It is great.

I need to get this working on many PCs. Is there already a package which does the enable SSH URLs?

4
  • No, but you can use whatever process you'll use to install such a package to instead run those commands.
    – muru
    Dec 17, 2015 at 8:29
  • I do not know of any package that does this, but if deploying to many instances, why not just make a shell script and run that on every machine? Dec 21, 2015 at 15:34
  • @robobenklein yes, running a script an all machines would work. But what happens to those machines which are down when I run my loop over all machines?
    – guettli
    Dec 21, 2015 at 15:56
  • @guettli how do you deploy packages? could you not also add a simple function to deploy a script? Otherwise, you could just package the script as an install for a .deb. Dec 21, 2015 at 18:55

1 Answer 1

7
+50

No, there is no package for this because there is already support for it, you just have to enable it.

To enable it in a gnome desktop: (How to open ssh://username@hostname link)

gconftool-2 --set --type=bool /desktop/gnome/url-handlers/ssh/enabled true
gconftool-2 --set --type=string /desktop/gnome/url-handlers/ssh/command 'gnome-terminal -e "%s"'
gconftool-2 --set --type=bool /desktop/gnome/url-handlers/ssh/needs_terminal false

My script to install the handler application:

#!/bin/bash
# We need root to install
if [ "$(id -u)" != "0" ]; then
  echo "This script must be run as root" 1>&2
  exit 1
fi

# In case file exists
if [ -f "/usr/local/bin/ssh-url-handler" ]
then
  echo "Found an old install, moving to ssh-url-handler.old"
  mv /usr/local/bin/ssh-url-handler /usr/local/bin/ssh-url-handler.old
fi

# Install handler file
touch /usr/local/bin/ssh-url-handler
echo '#!/bin/sh' >> /usr/local/bin/ssh-url-handler
echo 'd=${1#ssh://}' >> /usr/local/bin/ssh-url-handler
echo 'x-terminal-emulator -x bash -c "ssh $d" &' >> /usr/local/bin/ssh-url-handler
chmod a+x /usr/local/bin/ssh-url-handler

# Check that it is there
type ssh-url-handler >/dev/null 2>&1 || echo "Warning: the ssh-url-handler could not be found! Please check that /usr/local/bin is in the PATH"

# Now for the desktop piece:
if [ -f "/usr/share/applications/ssh-url-handler.desktop" ]
then
  echo "Found an old desktop handler, moving to .old"
  mv /usr/share/applications/ssh-url-handler.desktop /usr/share/applications/ssh-url-handler.desktop.old
fi

touch /usr/share/applications/ssh-url-handler.desktop
echo "[Desktop Entry]" >> /usr/share/applications/ssh-url-handler.desktop
echo "Type=Application" >> /usr/share/applications/ssh-url-handler.desktop
echo "Name=SSH URL Handler" >> /usr/share/applications/ssh-url-handler.desktop
echo "Exec=ssh-url-handler %u" >> /usr/share/applications/ssh-url-handler.desktop
echo "Icon=utilities-terminal" >> /usr/share/applications/ssh-url-handler.desktop
echo "StartupNotify=false" >> /usr/share/applications/ssh-url-handler.desktop
echo "MimeType=x-scheme-handler/ssh;" >> /usr/share/applications/ssh-url-handler.desktop
chmod a+x /usr/share/applications/ssh-url-handler.desktop

Just drop that into the install.sh of any debian package. You can easily do this using https://github.com/jordansissel/fpm/wiki to make your own package and distribute that.

2
  • Why is it not supported out of the box like the "mailto:" protocol?
    – guettli
    Dec 22, 2015 at 11:09
  • @guettli My guess is that the mailto: protocol is universal, and has many applications that handle it. The SSH protocol is not a common desktop mime application, and has a larger chance for a vulnerability to be found in using it. (Perhaps unwillingly connecting to a server with agent-forwarding, where the evil server then can use your private key.) Since most normal people won't be using it very often, it made sense not to leave any dangling ends lying around. Dec 22, 2015 at 14:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .