1. Log in to the system, issue the following commands and save their output for further reference
echo "$DISPLAY" xauth listYou will see something similar to this:
% echo $DISPLAY localhost:10.0
% xauth list
ubuntu/unix:12 MIT-MAGIC-COOKIE-1 9e7f2b822e5c1cdd96d048adfb870519
ubuntu/unix:11 MIT-MAGIC-COOKIE-1 1eaf535afee8b2de2f0ab9bcab7ef149
ubuntu/unix:10 MIT-MAGIC-COOKIE-1 3bd9602df5fe354c19e39f211ee4668b
Note the value after the semicolon in the DISPLAY value (10 in this case, in red), note that the last entry is the cookie you're interested in (also in red).
2. Switch the user (su ...), and run the following commands:
% su -
Password:
~# export DISPLAY=localhost:10.0 # this is the previously saved DISPLAY value
~# xauth add ubuntu/unix:10 MIT-MAGIC-COOKIE-1 3bd9602df5fe354c19e39f211ee4668b # this is the last entry from xauth list output
After this your X session should work.