Saturday, April 04, 2009

Exporting Display between Linux hosts

This tip may come handy in a network environment if you want to export the display of a linux machine to another to run tools or programs in GUI mode.Think of a scenario in which you are not having the access to the display of another machine and want to test a tool or application urgently in GUI mode.All you r left with is the display of your machine booted in graphical mode and a privilaged access to the machine you want to test the tool from.



Fig: Firefox executed from remote host

I have found this useful in current workplace where testing of tools in GUI mode is essential often as part of OS support we are giving to the developers.This is found to work in almost all linux flavours with some additions in some distributions.

Note that this is heavily dependant on the speed of your network connection. If u think u can run some application like mozilla off a box on the other side of the country on a 56K modem it is probably not going to work very well. The best application for this is running programs over the same standard LAN or possibly a high-speed WAN.

Background

For this we r going to assume the machine from which we r exporting display as remote host and machine to which we export as localhost (GUI login).

Steps

First ,on the local machine you're going to need to give the remote machine access to connect to your X server. Use the command xhost to do this in localhost:


// This command allows the machine remotehost to connect

# xhost +ip of remotehost
eg: #xhost +192.168.192.17

Secondly,on the remote machine, you need to export the $DISPLAY variable to your local machine. After that, you should be ready to run GUI programs remotely:

//This command allows the display of localhost to access that of remotehost

# export DISPLAY="ip of localhost:0.0"
eg: # export DISPLAY="192.168.192.10:0.0"

Now be ready to fire up the command of the tool/program in the shell of localhost after gaining access to the remotehost shell :
# ssh ajith@192.168.192.17  (Be sure to export the display specifically for the user)

# gvim & (Command for GUI tool)

Securing and encrypting the data

Note that This is very unsecure and not recommended since everything you type including passwords will be transmitted over the network unencrypted.To tunnel the connection over SSH and thus encrypt the traffic,edit your '/etc/sshd2_config' file.
(Refer your distribution manual for the right sshd  file)

In  /etc/sshd2_config of remote machine and local machine,

// Add or edit the following line as

ForwardX11     yes

Now connect from the local machine to the remote machine via ssh and start your X application.Notice that you don't have to set the DISPLAY variable, ssh automagically does that for you. You do however have to allow access to your local machine's X server (see above).

I happened to stumble on some issues raised in a forum on the topic : http://www.linuxquestions.org/questions/linux-networking-3/how-to-export-the-display-304667/