Skip to content

Instantly share code, notes, and snippets.

@darrenpmeyer
Created February 15, 2023 16:19
Show Gist options
  • Save darrenpmeyer/dca8012c7651c9fc1266d8b05a3ba489 to your computer and use it in GitHub Desktop.
Save darrenpmeyer/dca8012c7651c9fc1266d8b05a3ba489 to your computer and use it in GitHub Desktop.
HOWTO allow a specific local user access to your current X11 session

The Problem

You're happly running a desktop X11 session as user anne; but you want to be able to run an X11 application in that session as bob, but wehn you try to do this you get:

X-Server access is denied on host

The solution

Many articles will recommend disabling the xhost access controls. DON'T do this, as it allows anyone to connect to your X11 session. We can easily just allow bob to do that with:

xhost +si:localuser:bob

This allows just bob to access your current X11 display. Check your current display with:

echo "DISPLAY=$DISPLAY"

and note it (usually it's something like :0; that's the value we will use in the next couple example commands).

Then you can:

su bob
export DISPLAY=:0
xterm

Of course replace :0 with the actual value you noted from above, and xterm with whatever X11 application you're starting. That simple.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment