0

On a terminal (local terminal or ssh with X11 forwarding), a user can open X application however, another user is not able after suing.

Please see the output below.

u1@cluster:~$ xclock
u1@cluster:~$ su
Password:
root@cluster:# su - u2
[u2@cluster ~]$ xclock
No protocol specified
Error: Can't open display: localhost:11.0
[u2@cluster ~]$

So, what is the solution?

0

I usually create the following script in either /usr/local/bin or $HOME/bin.

#!/bin/bash
HOSTNAME=`uname -n`
ARG=`echo $DISPLAY | sed -e "s/localhost/$HOSTNAME\/unix/"`
XAUTH=`/usr/bin/xauth -i -f ~/.Xauthority list ${ARG}`

echo "The following is used for graphical displays through ssh."
echo "Copy and paste the following commands AFTER you have \"su - [user]\""
echo "----------------  Copy below  ------------------------------------"
echo "DISPLAY=$DISPLAY;export DISPLAY"
echo "/usr/bin/xauth -bi add \\"
echo "${XAUTH}"
echo "----------------  Copy above  ------------------------------------"

You would execute this script before using su or sudo. After becoming the other user, cut and paste the output as noted. Your X programs should run.

[bschuck@dhcp-10-100-11-138 ~]$ bin/xtunnel 
The following is used for graphical displays through ssh.
Copy and paste the following commands AFTER you have "su - [user]"
----------------  Copy below  ------------------------------------
DISPLAY=localhost:10.0;export DISPLAY
/usr/bin/xauth -bi add \
dhcp-10-100-11-138/unix:10  MIT-MAGIC-COOKIE-1 \
b64ace6b49bb1b49c59679a2db6411eb
----------------  Copy above  ------------------------------------
[bschuck@dhcp-10-100-11-138 ~]$ su - zippy
Password: 
[zippy@dhcp-10-100-11-138 ~]$ DISPLAY=localhost:10.0;export DISPLAY
[zippy@dhcp-10-100-11-138 ~]$ /usr/bin/xauth -bi add \
> dhcp-10-100-11-138/unix:10  MIT-MAGIC-COOKIE-1  
b64ace6b49bb1b49c59679a2db6411eb
[zippy@dhcp-10-100-11-138 ~]$ xclock &
[1] 6076
[zippy@dhcp-10-100-11-138 ~]$
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.