X11 forwarding does not work if su to another user

puttyrhelx11xming

I have a Red Hat 7.3 server running XVnc. On a Windows 10 desktop I have Putty and Xming installed. Putty is configured for X11 forwarding. When I SSH in as my standard/non-privileged user and launch an X application, it displays on my Windows 10 desktop without issue.

Now within same session, if I su to a more privileged account and try to run an X application, it fails with "error: can't open display".

In my standard user session if I echo $DISPLAY it is automatically set for me as "IP_ADDRESS:10.0". Under my su session, $DISPLAY is null. I tried exporting the DISPLAY variable to the same value but it now a different error appears: "PuTTY X11 proxy: Unsupported authorization protocol Error: Can't open display:server_IP:10.0".

How can I configure the X11 forwarding to work under the context of the other user?

Best Answer

The below steps should fix the issue for you.

Say it's working for user1 and you want to use it for user2

For user1:

$ xauth list $DISPLAY
<output1>
$ echo $DISPLAY
<outoput2>

Switch to other user , i.e user2

$ xauth add <output1> 
$ export DISPLAY=<output2>

Try:

$ xclock
Related Question