X forwarding after su

jplindstrom on 2005-06-02T09:33:35

This was new. X forwarding broke after I su'ed to another user. What previously worked says

Connection lost to X server `localhost:10.0'


after a su. It's the magic cookie that isn't there for the new user. So, how to add the cookie for the new user?

echo $DISPLAY
localhost:10.0


We're on 10.

xauth list
Hostname/unix:10  MIT-MAGIC-COOKIE-1  f4bb4714280c22018cacd461277dd760


Copy the entire line for the display and su to your user.

xauth add Hostname/unix:10  MIT-MAGIC-COOKIE-1  f4bb4714280c22018cacd461277dd760


And xclock works!


Re:

Aristotle on 2005-06-03T05:13:18

Easier:

xauth extract - "$DISPLAY" | su otheruser -c 'xauth merge -'

Insert the requisite mention of ssh if you’re doing this across the network, etc.

Re:

jplindstrom on 2005-06-04T20:24:25

Excellent, thanks!