Run commands as another user, with access to the X display

I've uploaded a simple wrapper around sudo, for executing commands as another user with full access to the X display (GLX works too); I call it xudo.

The script basically does two things:

  • Authorize the user:
    xauth extract - $DISPLAY | sudo -u SOMEUSER xauth merge -
    
  • Run the command preserving the DISPLAY environment variable:
    sudo DISPLAY="$DISPLAY" -u SOMEUSER SUDO_OPTIONS
    

    And you can of course use the -i or -s sudo options to get a shell as the other user, from where you can launch graphical applications.

All the other bits in the script are really just boilerplate.

Keep in mind that security-wise this is indeed a little stricter than the xhost +local: and xauth generate combination, as it authorizes only the user you want, but the command you execute still gets access to the whole X server, so you still don't want to run programs you don't trust using this method.


CommentsSyndicate content

Post new comment

The content of this field is kept private and will not be shown publicly. If you have a Gravatar account associated with the e-mail address you provide, it will be used to display your avatar.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
3
p
V
K
s
u
Enter the code without spaces.