I need to connect to several VNC servers in a configuration like this:

|HOST2        |
|VNC 5901:5901|
|HOST3        |
|VNC 5902:5901|
  • Localhost: My laptop running Windows
  • Host1: A Linux host which I connect through SSH. This host is connected to the same network than host2.
  • Host2: This Linux host is running one of the VNC servers letting port 5901 open. Is connected to host1 using network1 and to host2 using network2. Runs Linux.
  • Host3: This Linux host runs the other VNC server, letting port 5901 open. Is connected to host2 using network2. Runs Linux.

So, in order to connect to the VNC servers I'm running some SSH tunnels to redirect traffic in ports 5901 and 5902.

Commands to tunnel look like this:

# Terminal 1
ssh user1@host1
ssh user2@host2
ssh -L 5902: -C -N -l user3 host3 -vvv

# Terminal 2
ssh user1@host1 
ssh -L 5902: -C -N -l user2 host2 -vvv

# Terminal 3
ssh user1@host1 
ssh -nNT -L 5901:host2:5901 user1@host1 -vvv

# Terminal 4
ssh -L 5902: -C -N -l user1 host1 -vvv

# Terminal 5
ssh -nNT -L 5901:host1:5901 user1@host1 -vvv

(Bit of a messy commands, but hey, they work)

In every terminal, this would prompt a message to type the password of the user and will keep a process running until is aborted or a connection timeout happens.

So this works fine and I'm able to connect to VNC servers from my laptop using localhost:5901 and localhost:5902.

The problem is, I have to type a lot of this commands, type the same passwords over and over, opening several terminals that keep open, several times a day (because of connection timeouts), and its getting old real fast.

So I was wondering if this could be automated somehow, the requirement being that whatever script or program could dive deep into several hosts running commands, some of them prompting passwords that needs to be typed, and some of this process will keep running until Ctrl+C is pressed.

I'm asking for names of programs or bash commands that can be used to automate this kind of scenarios so I could research a solution. Thanks.

  • 1
    What about creating keypairs, putting the public keys on the servers, add them to the list of autorized keys. On the client side, put hostnames and prvate-key file-names in~/.ssh/config? Voilà, no more password prompts.
    – knb
    Commented Sep 3, 2021 at 14:08

1 Answer 1


Using a GUI based application you can use Tabby.

Tabby allows you to define connection profiles, and it allows you to link profiles as jump-profile.

So after you define the connection for HOST1, you can then define HOST2 with HOST1 as it's jump host, and HOST3 with HOST2 as it's jump host.

For command line, you can keep on using SSH, just configure the tunnels and ProxyJump hosts in the ~/.ssh/config file, here is an example:

Host _host1
  Hostname host.fqdn
  User username1
  Port 22

Host _host2
  Hostname host2.fqdn
  User username2
  ProxyJump _host1
  LocalForward 5091 localhost:5091

Host _host3
  Hostname host3.fqdn
  User username3
  ProxyJump _host2
  LocalForward 5092 localhost:5091

And then from the command line run:

ssh _host3
  • 1
    Thanks a lot, just tried and this program is perfect, it will make my life much more easy.
    – ordago
    Commented Sep 9, 2021 at 7:56
  • 1
    I agree, this has been a quality-of-life change for me as well, and the maintainer is still actively adding features and fixing things, it gets better and better with every version.
    – Lockszmith
    Commented Sep 9, 2021 at 17:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.