07 December 2011

Forwarding X11 through multiple SSH connections

Graphical Applications on a GNU/Linux machine can be launched from the remote machine to appear on your local machine by using 'X11 Forwarding', with X11 (or Xorg) being the name of the software that makes graphics possible on a GNU/Linux machine.  Your desktop such as KDE or GNOME or whatever is the client which connects to the X11 server.  There is now Wayland in the works, to replace Xorg/X11, but this won't cover that.

Because this is a client/server relationship, the two don't need to be running on the same machine.  We can start a remote graphical app from a command line and run the processing power on that remote machine (the server), while seeing and working on that app at the local machine (the client).

Let's first get an SSH connection with X11 forwarding started using the -X flag:
local-shell$  ssh user@remote.server.com -X
password: **********
remote-shell$
remote-shell$  dolphin
Connecting to deprecated signal QDBusConnectionInterface::serviceOwnerChanged(QString,QString,QString)
kbuildsycoca4 running...



Here is a partial screenshot of this; the front Dolphin is the remote Dolphin (@bigboi) and running KDE 4.7.2 and with its specific layout, while the Dolphin in the back is the locally-running Dolphin (KDE 4.4.5 on Squeeze).
Click to Enlarge
Note the Dolphin in the foreground has its window management handled by the local machine (we can see the colour mismatch), but other aspects such as icons and contents belong to the remote machine.

To run X11 graphics across two connections, however, requires a bit of TTY-forwarding (using the -t flag, multiple times).  This tip allows us to connect to one machine, say a network gateway, and from that machine run a command to connect to our office desktop.  From here we can launch a graphical application and have it appear on our local machine.
local-desktop$  ssh -X -t -t -t lefty@gatewaymachine.com "ssh employee@192.168.1.00 -X"
lefty@gateway's password:
employee@192.168.1.100's password
employee-desktop$

This can come in very handy and it allows X applications to be run through a complex firewall scheme.  That command is a single line:


ssh -X -t -t -t lefty@gatewaymachine.com "ssh employee@192.168.1.00 -X"

0 comments: