Here is my situation:
I have two (sudo) users on a machine:
userA(created first on the machine. This is also where display:0is attached)userB(created later)
Being on userA I do:
export DISPLAY=:0.0
xclock
And the clock opens on DISPLAY:0 as intended.
Now, I want the same steps to work on userB. But unfortunately, it shows:
No protocol specified
xhost: unable to open display ":0.0"
What I tried:
- Creating a trusted xauth key using:
xauth generate :0.0 . trustedwhich again showsunable to open display ":0.0" - Copying the
/home/userA/.Xauthorityto/home/userB/.Xauthority. (Note: I did not see any key pertaining to display :0 in theuserAxauth list, even though it works.) - Creating trusted xauth key for
:0onuserAand copying that key touserB.
None of these worked.
What worked:
- I log-in to
userA. Iexport DISPLAY=:0.0and thenxhost +to enable access from all clients. - I log back in to
userB. Iexport DISPLAY=:0.0and thenxclock.
I want to eliminate Step 1. I do NOT want to log-in to userA each time. And I did try to xhost + from userB, which shows error already shown above.
How can I run xhost + from userB, while also making it think it has the DISPLAY:0 access?
Edit: As mentioned by @user414777, I was able to:
# On userA
$ xhost +si:localuser:userB
# On userB
$ export DISPLAY=:0.0 ; xclock
And make it work. But these changes don't stay post-reboot.
# After rebooting, on userB
$ export DISPLAY=:0.0 ; xclock
Invalid MIT-MAGIC-COOKIE-1 keyError: Can't open display: :0.0
I'm running Ubuntu 18.04 LTS, 4.18.0-15-generic
SOLVED
I eventually went with a slightly insecure and modified suggestion by @user414777. Instead of adding the change in ~/.xsession or Xsession.d, I added that line in /etc/profile, which applies the change for all users.