Monday, November 10, 2014

X11 forwarding

This blog is about X11 forwarding. This comes in handy when you want to see the graphical interfaces of X11 programs running on a remote Linux server to be displayed on a local client machine. I am not an Linux expert so it took some time for me to set this up, so I thought of writing it in blog for future references.

Need ?

I came across the need to do X11 forwarding for one of my project. I had a remote access to the linux server and my task was to install one of the Oracle FMW product. During installation, graphical wizards comes for the configuration settings and this is the place where you require X11 forwarding.
When you connect to linux server via SSH and try to run the graphical applications you will get the error - Can't open display. Basically when you SSH in and run a graphical application, it has no location in which to draw the window. To put it another way, there is no display associated with that connection.In order to get the instructions on how to draw the window sent back over the network to our computer the SSH client needs to be configured to request them.

How to solve the problem ?

Problem can be fixed by following 2 steps -
1. Requesting the remote linux server to forward X connections - Configure the SSH client to send the instructions to draw the GUI sent over the network to the client machine.

2. Running an X server on the client machine to listen for the connections - The role of the X server is to make sense of the instructions coming from remote Linux server and translate them into commands that can be drawn by Windows.

Prerequisites 

  • Install putty and configure for SSH.
  • Install Xming server on your Windows PC. You can download it from Sourceforge link.

Configuration Steps

1 Set X11 forwarding in your putty session



2. SSH to the remote Linux server and follow the below steps.

i) Before issuing the su or sudo, request the cookie for the current DISPLAY to connect to your Xming server

$xauth list
host/domain:10 MIT-MAGIC-COOKIE-1 HEX-KEY

For Ex:
$ xauth list
atloraman/unix:10  MIT-MAGIC-COOKIE-1  926b224b5afc20f8db4bf06c0ef6a6c8


Note: Above output will be different for every session

ii) Switch to atladmin or oracle account
    $ su - atladmin

   Export your DISPLAY variable
  $ export DISPLAY=localhost:10.0

iii) Add the output string from the xauth list command above:

$ xauth add displayname protocolname hexkey

For Ex:
$ xauth add atloraman/unix:10  MIT-MAGIC-COOKIE-1  926b224b5afc20f8db4bf06c0ef6a6c8

Run xclock to verify your X11 session is working





iv) When you don't need the access, execute the below command -
xauth remove $DISPLAY