Friday, February 12, 2016

Remote control a linux desktop with ssh

To control single windows you can use X11forwarding.
ssh -X REMOTESERVER
For this to work on the server XForwarding has to be enabled.
Check /etc/ssh/sshd_config and make sure X11Forwarding yes is present.

That's it. You can now start graphical applications on the server and they show up on your client.



To control the whole desktop you can use x11vnc (over ssh).

First make sure x11vnc and sshd are installed on the server.

On the client:
ssh -C -t -L 5900:localhost:5900 REMOTESERVER 'x11vnc -localhost -nap -wait 50 -noxdamage -display :0 -forever'
This connects to the server, starts x11vnc to only allow local connections and tunnel the port back to the local (client) port 5900 while compressing the data (-C) to speed it all up. This way only you can connect to the remote X11 session by using a vncviewer of your choice.
vncviewer -encodings "copyrect tight zrle hextile" localhost:0

That's it.