Home > IT Architecture, Linux, Systems > Use xming, xshell, putty, tightvnc to display linux gui on windows desktop (x11 forwarding when behind firewall)

Use xming, xshell, putty, tightvnc to display linux gui on windows desktop (x11 forwarding when behind firewall)

May 24th, 2011

Q1:How do I run X11 applications through Xming when there's no firewall?

Step 1 - Configure Xming

Let's assume that you want to run xclock on solaris/linux server 192.168.0.3, and want the gui display on your pc whose ip is 192.168.0.4.

Firstly, download xming, install it on your windows pc system.

You can go to http://sourceforge.net/projects/xming/files/ to download.

After this, you need set 192.168.0.3(linux/solaris) to the allowed server list on your windows. Edit X0.hosts which locates at the installation directory of xming(For example, C:\Program Files\Xming\X0.hosts), add a new entry in it:192.168.0.3, the ip address of linux/solaris that you want to run x11 utility from.

Then, restart xming(C:\Program Files\Xming\xming.exe) on your windows.

Step 2 - Connect to remote host, configure it, and run X11 application

Log in linux/solaris server 192.168.0.3. Set environment variable DISPLAY to the ip address of your windows, and append a :0 to it:

#export DISPLAY=192.168.0.4:0

Then you must allow X11 forwarding in sshd configuration file. That is, set X11Forwarding to yes in /etc/ssh/sshd_config and restart your sshd daemon.

 And on solaris/linux server(192.168.0.3), run a X11 programe, like

/usr/bin/xclock #or /usr/openwin/bin/xclock on solaris

You will then see a clock gui pop up in your windows pc.

PS: You may need install xorg-x11-xauth on remote host sometimes if you met error starting up xclock

Q2:How do I run X11 applications from remote host when that host is behind firewall?

If the remote host is behind firewall, then the method above will not work as the communication will be blocked if no firewall exception implemented. To run X11 applications from remote host behind firewall, you can follow steps below:

Step 1 - Configure Xming

This step is the same as step 1 in Q1, but I'll paste it here for your convenience:

Let's assume that you want to run xclock on solaris/linux server 192.168.0.3, and want the gui display on your pc whose ip is 192.168.0.4.

Firstly, download xming, install it on your windows pc system.

You can go to http://sourceforge.net/projects/xming/files/ to download.

After this, you need set 192.168.0.3(linux/solaris) to the allowed server list on your windows. Edit X0.hosts which locates at the installation directory of xming(For example, C:\Program Files\Xming\X0.hosts), add a new entry in it:192.168.0.3, which is the ip address of linux/solaris that you want to run x11 utility from.

Then, restart xming(C:\Program Files\Xming\xming.exe) on your windows.

Step 2 - Configure X11 forwarding on putty/xshell

For Xshell:

After entering remote hostname and log on username on Xshell, now nn the Tunneling tab of Advanced SSH Options dialog box, check "Forward X11 Connections to:" and click on "X DISPLAY:" and enter "localhost:0.0" next to it.

xshell_x11_forwarding

For Putty:

After entering remote hostname and log on username on putty, now unfold "Connection" on the left pane, unfold "SSH, and then select "X11". Later, check "Enable X11 forwarding" and enter "localhost:0.0" next to "X display location".

putty_x11_forwarding

Step 3 - Connect to remote host, configure it, and run X11 application

Log in linux/solaris server 192.168.0.3. Set environment variable DISPLAY to localhost:0

#export DISPLAY=localhost:0 #not 192.168.0.4:0 any more!

Then you must allow X11 forwarding in sshd configuration file. That is, set X11Forwarding to yes in /etc/ssh/sshd_config and restart your sshd daemon.

And on solaris/linux server(192.168.0.3), run a X11 programe, like

/usr/bin/xclock #or /usr/openwin/bin/xclock on solaris

You will then see a clock gui pop up in your windows pc.

PS: You may need install xorg-x11-xauth on remote host sometimes if you met error starting up xclock

Q3:How do I connect to remote host through vnc client(such as tightvnc)?

In general, you need first install vnc-server on remote host, then configure vnc-server on remote host. Later install tightvnc client on your PC and connect to remote host.

I'll show details about install vnc-server on remote host below:

yum grouplist
yum groupinstall "X Window System" -y
yum groupinstall "GNOME Desktop Environment" -y
yum groupinstall "Graphical Internet" -y
yum groupinstall "Graphics" -y
yum install vnc-server
echo "DESKTOP="GNOME"" > /etc/sysconfig/desktop
sed -i.bak ‘/VNCSERVERS=/d’ /etc/sysconfig/vncservers
echo "VNCSERVERS=\"1:root\"" >> /etc/sysconfig/vncservers

mkdir -p /root/.vnc
vi xstartup

#!/bin/sh

# Uncomment the following two lines for normal desktop:
# unset SESSION_MANAGER
# exec /etc/X11/xinit/xinitrc

[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &
#xterm -geometry 80×24+10+10 -ls -title "$VNCDESKTOP Desktop" &
#twm &
gnome-terminal &
gnome-session &

vncpasswd ~/.vnc/passwd #set password
chmod 755 ~/.vnc ; chmod 600 ~/.vnc/passwd ; chmod 755 ~/.vnc/xstartup

chkconfig –level 345 vncserver on
chkconfig –list | grep vncserver
service vncserver start

Q4:What if I want one linux box acting as X server, another linux box as X client, and I'm not sitting behind the Linux X server(means I have to connect to the Linux X server through VNC)?

This may sound complex, but it's simple actually.

First, you need install vnc-server on the linux X server following steps in above "Q3: How do I connect to remote host through vnc client(such as tightvnc)?".

Second, install tightvnc viewer on your windows box you sit behind and connect to the linux X server through it(xxx.xxx.xxx.xxx:1 or example). Run xhost + <linux X client> to enable access to X server.

Then, on the linux X client, export DISPLAY to xxx.xxx.xxx.xxx:1 which is the linux X server. Run a X program such as xclock, and you'll see the clock displaying on the X interface on your windows tightvnc viewer.

PS:

1.You can change vncserver’s resolution through editing /usr/bin/vncserver, change the default $geometry = "1024×768″ to any one you like, for example $geometry = "1600×900″. You can also control each user’s vnc resolution setting through adding line like "VNCSERVERARGS[1]="-geometry 1600×900″" in /etc/sysconfig/vncservers

2.For vnc server on ubuntu, you can refer to http://www.doxer.org/ubuntu-server-gnome-desktop-and-vncserver-configuration/

Problem resolved?


  1. Tom Tobin
    July 27th, 2011 at 20:22 | #1

    Thank you, from the bottom of my heart. I have been trying to get this to work for a couple of days now, from bits and pieces scattered all over the net.
    This is the first cohesive posting I have seen, that made everything work.
    It’s much appreciated!!!

    • Anonymous
      July 28th, 2011 at 23:20 | #2

      You’re welcome. Good luck!

  2. Casolisco
    February 9th, 2012 at 17:38 | #3

    Great!
    =)
    Thnx a lot!!

  3. Wtrnymph
    June 27th, 2012 at 10:13 | #4

    This is an absolute guide…I had to murk thru quite a bit before I got it. Thank you so much!

    • doxerorg
      June 27th, 2012 at 11:47 | #5

      Glad this helped, good luck!

    • doxerorg
      June 27th, 2012 at 11:47 | #6

      Glad this helped, good luck!

  4. Jayesh
    August 27th, 2012 at 10:13 | #7

    I did this, everything works fine except clipboard.
    I cannot copy text from xming (say gvim opened in xming) to xshell window, but I can copy it to any other windows application like msword. Please let me know how to fix this.

    • March 21st, 2014 at 13:13 | #8

      Hi,
      Maybe you could try tightvnc & vnc-server. That support clipboard definitely as I used it a lot.

  5. HS
    February 22nd, 2013 at 01:52 | #9

    Amazing.. Worked like a charm !! Cheers..

  6. Abhinav
    June 3rd, 2013 at 10:59 | #10

    I am creating a GUI in java swing on linux client machine which creates a ssh connection to the remote linux server on button click and execute a command “java -jar GUITest.jar”, But i am not able to see the GUI of GUITest.jar. I am using Jsch library for SSH connection.
    Same thing i am able to do in windows,i have used same java code and there i am running Xming server which opens GUI automatically on client machine but the application actual runs on server. please provide me the solution.

  1. May 25th, 2011 at 01:56 | #1
  2. March 21st, 2014 at 13:20 | #2
  3. March 21st, 2014 at 13:21 | #3