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 :
- initiate a "secure tunnel" from remote to local, using the "reverse" ability of SSH
- initiate a connection from local to remote using the tunnel we just opened
- 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
- Install it through your package manager (for example
# apt-get install x11vncon Ubuntu/Debian)
- Generate a password
$ mkdir ~/.x11vnc $ x11vnc -storepasswd password ~/.x11vnc/passwd
- In a running X session, run the vnc server
$ x11vnc -display :0 -rfbauth ~/.x11vnc/passwd
- 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.
- Install a viewer on the local side (for example
# apt-get install vncvieweron Ubuntu/Debian)
- Initiate a connection to distant through the tunnel
$ ssh distant_user@localhost -p 12345 -L 5901:localhost:5900
- 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!