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/allen/scripts/ssh-handler.sh
#!/bin/bash
echo $1 &>> /home/allen/result1
d=$(echo ${1#*ssh://}|awk -F: '{print $1}') 
echo $d &>> /home/allen/result1
#gnome-terminal -e "ssh $d" &
/usr/bin/gnome-terminal -e "ssh -p 4422 $d" & &>> /home/allen/result1

Bash

Copy

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/allen/scripts/ssh-handler.sh %u
Icon=utilities-terminal
StartupNotify=false
MimeType=x-scheme-handler/ssh

Bash

Copy

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

Bash

Copy

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

<a href="ssh://394e507ad03a4ad0cf381126@pam.***.com.au:4422">LINK</a>

Markup

Copy

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:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值