Sunday, November 21, 2010

How to invoke xterm from putty?

When we connect to a Linux/Solaris or any Unix servers using putty from Windows machine and try to access any X applications like xterm, xeyes, etc it may throw errors like

Xlib: connection to "localhost:10.0" refused by server
Xlib: PuTTY X11 proxy: wrong authentication protocol attempted
Error: Can't open display: localhost:10.0
or
X connection to localhost:10.0 broken (explicit kill or server shutdown)

Then you need to install Xming on your Windows machine. Xming is the X Window Server for Microsoft XP/2008/Windows7.

Start Xming in your windows machine and now login to your Unix machine through putty
For Ex:
#ssh root@spodumene.ap.rsa.net
[root@spodumene build]# xeyes

Here xeyes is a simple X application, which displays a pair of eyes. If it displays this, then you can start any  X applications.

But still you may get issues if you login as root and then do "su - user" and try to access X application.

[root@spodumene build]# su - build
[build@spodumene ~]$ xeyes
Xlib: connection to "localhost:10.0" refused by server
Xlib: PuTTY X11 proxy: wrong authentication protocol attempted
Error: Can't open display: localhost:10.0

You need to temporarily transfer the authorization to the other account. First, get the key from your account
To fix this, do following. Login as root and call "xauth list" command.
[root@spodumene build]# xauth list
spodumene.ap.rsa.net/unix:12  MIT-MAGIC-COOKIE-1  e0190c6d94addb5201f3d8cbeef32b72
spodumene.ap.rsa.net/unix:13  MIT-MAGIC-COOKIE-1  b1e7ee620ddef216e32cff36945a31a0
spodumene.ap.rsa.net/unix:11  MIT-MAGIC-COOKIE-1  5db41fd092612581a408a762e252494b
spodumene.ap.rsa.net/unix:10  MIT-MAGIC-COOKIE-1  bb6f1099c09e630fd5caed5dc7b8d143


Now do "su" to your account
[root@spodumene build]# su - build

 And add auth tokens listed in the previous command using "xauth add" command.
[build@spodumene ~]$ xauth add spodumene.ap.rsa.net/unix:10  MIT-MAGIC-COOKIE-1  bb6f1099c09e630fd5caed5dc7b8d143


You can repeat this for remaining tokens. After that run "xauth list", which will display all the added tokens.
[build@spodumene ~]$ xauth list
spodumene.ap.rsa.net/unix:10  MIT-MAGIC-COOKIE-1  bb6f1099c09e630fd5caed5dc7b8d143
spodumene.ap.rsa.net/unix:12  MIT-MAGIC-COOKIE-1  e0190c6d94addb5201f3d8cbeef32b72
spodumene.ap.rsa.net/unix:13  MIT-MAGIC-COOKIE-1  b1e7ee620ddef216e32cff36945a31a0
spodumene.ap.rsa.net/unix:11  MIT-MAGIC-COOKIE-1  5db41fd092612581a408a762e252494b

Now run your X application
[build@spodumene ~]$ xterm

It will open an xterm.

8 comments:

Anonymous said...

Thanks Siddesh, It really helped me I was pissed off not knowing it require xming for x11 from window/putty as client. Every other blog I read, no body told me that there is difference when you try to connect from window putty and from linux machine.
Thanks
ketan

Vinoth - Oracle DBA said...

Thanks Siddesh ....It helpmed me a lot...

Anonymous said...

Thanks siddesh for solution it worked for now

Sunil

Mai Thanh Hai said...

Thanks Siddesh, It work. But I don't understand the command. Can you help me(may be a link).

Hampton said...

Thanks Siddesh ....It helpmed me a lot...

Anonymous said...

Thanks Siddesh, this helped me.

Question: Would you know why the xclock wont display if I use sudo?

Aditya said...

Excellent explanation! thank you!

Anonymous said...

bad explanation. xming doesn't help at all