Open SSH forward ports from desktop (not in a terminal)

spoovy asked:

For reasons I won’t go into I often have to set up multiple SSH tunnels to a remote box — often enough that it would be nice to be able to initiate it with a single command from a desktop launcher (I use GNOME Do).

Currently I have .ssh/config set up with the following (snipped a little and anonymised):

Host hawkeye
  Port 22
  User thedudeabides
  IdentityFile ~/.ssh/id_rsa
  LocalForward 8888
  LocalForward 4845
  LocalForward 4093

..and I open a terminal and run ‘ssh hawkeye’, which sets up tunnelling and leaves me ssh’d into hawkeye.

Problem is (small problem, granted) is that I often don’t want the remote console session opened, and I’d like to be able to set these tunnels up with a single command from GNOME Do, so the tunnels are set up and backgrounded, but no terminal is opened.

I’ve tried scripts using various SSH flags but it never works as intended.

Any help appreciated.

My answer:

Use ssh -N hawkeye, as specified in the man page:

     -N      Do not execute a remote command.  This is useful for just for‐
             warding ports (protocol version 2 only).

View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.