I want to open ssh:// links from Firefox with script that opens gnome-terminal and initiates SSH connection. Script works as intended when run manually but not if run from Firefox.
I use script found here: https://gist.github.com/jnaskali/104cc00d8e9dfc63cac1d9534ebc00a2
Here's my version:
#!/bin/bash
# Script that opens ssh:// links from Firefox - CC0 by Juhani, www.naskali.fi
{
# extract the protocol
proto="$(echo $1 | grep -oP '^[a-z]*')" # first letters
# extract the user (if any)
user="$(echo $1 | grep -oP '(?<=:\/\/)(.*)(?=@)')" # text in between :// and @
# extract the host
host="$(echo $1 | grep -oP '(?<=:\/\/|@)([a-z0-9\.]+)(?!.*@)')" # alphanumerals preceded by :// or @, not followed by text@
# extract the port
port="$(echo $1 | grep -oP '(?<=:)\d*')" # numbers after :
command="$proto "
if [ -n "$port" ]
then
command="${command}-p $port "
fi
if [ -n "$user" ]
then
command="${command}${user}@"
fi
command="${command}$host"
echo $PATH
gnome-terminal -- bash -c "$command"
} > sshtest 2>&1
# You also need the boolean 'network.protocol-handler.expose.ssh':false in Firefox's about:config
The script works as intended when run from terminal:
user@machine:~$ ./firefox_ssh_handler.sh ssh://admin@*.*.*.*
opens a new window and initiates SSH connection.
The problem: If I use the script as protocol handler in Firefox to open ssh:// link, the script runs, but does not open gnome-terminal. I get error gnome-terminal: command not found
on stderr.
I suppose this might be some security measure to prevent custom protocol handlers from opening terminal windows?
I'm running Ubuntu 22.04.1 LTS and Firefox 108.0.2
Some more information to rule out possible causes:
gnome-terminal is installed in /usr/bin, which is in $PATH, even if run from Firefox. If I use /usr/bin/gnome-terminal
in script, I get /usr/bin/gnome-terminal: No such file or directory
on stderr.
Firefox runs under the user that owns the script file. File permissions are -rwxrwxr-x
.
- network.protocol-handler.expose.ssh is set to "false".