Skip to main content

Remote viewing of session through VNC and reverse SSH

2 min read

Imagine you have a computer behind a router, called remote and a computer with a physical access, called local. What if you want to see remote's X session (an X session is a graphic session in Linux)?

One way to do it is to :

  1. initiate a "secure tunnel" from remote to local, using the "reverse" ability of SSH
  2. initiate a connection from local to remote using the tunnel we just opened
  3. tell VNC to use the last connection to get the remote X session

To prepare the ground, we first have to install a vncserver on the remote machine. I installed x11vnc. If you're running ArchLinux, we can find all the information on To configure it :

    1. Install it through your package manager (for example# apt-get install x11vnc on Ubuntu/Debian)
    2. Generate a password
      $ mkdir ~/.x11vnc
      $ x11vnc -storepasswd password ~/.x11vnc/passwd
    3. In a running X session, run the vnc server $ x11vnc -display :0 -rfbauth ~/.x11vnc/passwd
    4. Finally, initiate a reverse SSH tunnel to the local machine $ ssh -R 12345:localhost:22 local_user@local_adress

On the local side, do as follow.

  1. Install a viewer on the local side (for example# apt-get install vncviewer on Ubuntu/Debian)
  2. Initiate a connection to distant through the tunnel $ ssh distant_user@localhost -p 12345 -L 5901:localhost:5900 
  3. Finally, you can launch the viewer $ vncviewer localhost:1, the password you entered in point 3 of the configuration of the server is going to be asked.

You should now have the distant session opened in a window on the local machine!