Sometimes you need to run X applications from a console. You have :
– X11 Forwarding enabled on server side and requested on client connection
– X server is started on the client side
– DISPLAY variable set
You test X server (xclock, xterm…) and all is fine… Then for a reason or another you need to change the current user and… X Forwarding no longer works…
Despite all stuff set any application requiring X hangs or fails with messages like this :
Xlib: connection to "localhost:11.0" refused by server and/or Error: Can't open display: 192.168.XXX.XXX:0.0 and/or Error: Couldn't find per display information
etc… And xhost + command did not help…
Here is a “worth-to-try” workaround (solution ?) that helped me a lot yet :
1. Connection as first user
user1@server $ echo $DISPLAY && xauth -i list localhost:10.0 server/unix:11 MIT-MAGIC-COOKIE-1 9b5c0501c1cc11048d94e318377d3a6f server/unix:10 MIT-MAGIC-COOKIE-1 3cd5ca881727145e1d53434385af2199
Note accurately the DISPLAY result and the whole line matching it, ie the line which has the same display number (here “10″).
2. You perform some user changes (here root then user2) :
user1@server $ su - Password:****** NOTE: You are super-user root@server # su - user2
3. As user you want run X apps with then use 1st user information you grabbed :
user2@server $ export DISPLAY=localhost:10.0 user2@server $ xauth -i add server/unix:10 MIT-MAGIC-COOKIE-1 3cd5ca881727145e1d53434385af2199
4. Now try :
user2@server $ xclock Warning: Missing charsets in String to FontSet conversion Warning: Unable to load any usable fontset
Then It should work =)


