HOWTO: Display ‘X Windows’ programs on remote machines by forwarding ‘X’ connections through ssh
Purpose: Many times you may be in situation where you need to display/run your programs (typically ‘X Windows’ program) on a remote machine from your host (or current) machine.
Scenario: Let’s first set-up the scenario in order to better understand this example
Machine 1 – is the machine on which you would like to display the program/window of Machine2
IP address of Machine 1- 192.168.0.100
Machine 2 – is the machine whose display you are going to forward to Machine 1
IP address of Machine 2- 192.168.0.200
Further, I am assuming that both the machines have Debian (Etch or Lenny) installed with ‘X windows’, ‘xdm’ login manger and fluxbox. Although you can have any display or window manager of your choice (Xfce, GNOME, KDE, etc.)
Step 1:
On Machine 1 do the following:
a) If you are using xdm as login manager do:
# nano /etc/X11/xinit/xserverrc
It should look like this:
#!/bin/sh
# $Id: xserverrc 189 2005-06-11 00:04:27Z branden $
exec /usr/bin/X11/X -nolisten tcp
Now remove the line “-nolisten tcp” which basically tells X to allow “TCP” connections to itself (Machine 1).
Just logout and log back in to activate the above setting.
b) If you are using GDM as login manager do:
i) Logout
ii) Go to “Actions->Configure the login manager-> <Enter Password> ->Security”
Un-check the option “Deny TCP connections to Xserver” like this:

Uncheck Deny TCP connection
Click “OK” and log back into your system (GNOME/KDE/Fluxbox)
iii) Give the following command from a terminal window:
#xhost + <ip-address-of-machine2>
Example:
#xhost + 192.168.0.100
192.168.0.148 being added to access control list
Step 2:
On Machine 2, give the following command:
# export DISPLAY=<ip-address-of-machine 1>:0.0
Example:
# export DISPLAY=192.168.0.100:0.0
# echo $DISPLAY
192.168.0.100:0.0
The above steps tells X Window system that all the displays should be exported to Machine whose IP address is 192.168.0.100 on it display window ’0′
Step 3:
From Machine 2, run any ‘X’ based utility. I chose to run ‘xclock’ which basically displays a small clock window.
# xclock
And now the magic happens. Normally you would see the display on the same machine (machine 2) but hey, wait……….look at the screen of Machine 1……you should be able to see the clock there….

Step 4: (optional Method)
Instead of step 3 you can also achieve the same by doing the following:
# ssh -X root@<ip-address-of-machine2>
Example:
# ssh -X root@192.168.0.200
It will log you to shell of Machine 2. Now give the command ‘xclock’:
Machine2># xclock
As usual, please leave a comment/feedback if you have any. Comments encourages bloggers to post more and keep their spirits high.
Also please don’t forget to rate this post below.


Email Subscription









February 19th, 2009 at 8:07 am
I have Fedora 7 installed on my system.I am trying to run a C program with SDL graphics which loads an image and displays it.I want to display the image on remote machine.I login through rsh.i am able to execute xeyes but when I run this program it gives me an SDL error saying the video mode could not be initialised.please help…
Thanks in advance
Reply to this comment
Kushal Reply:
February 24th, 2009 at 1:07 am
Hi Shankar,
Thank you for your comment!
Looks like your systems are setup to display remote apps. Can you paste the exact error message that you are getting? I am not an expert in C/SDL graphics stuff but may be seeing the exact error messages might give some more clues.
Reply to this comment
February 24th, 2009 at 3:29 pm
Thanks for the reply Kushal.
I have figured out what the problem was. my program was unable to set the display device to the remote machine. when i changed the DISPLAY variable i was able to get the output….
Thanks for your time
Shankar
Reply to this comment