Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How to start an X server as root with a session of non-root application?

Should be something like

xinit 'su -c openbox user' -- :1

but working :)

share|improve this question


su -c 'startx openbox -- :1' user

Edit: Also try running

X :1 &
su -c 'DISPLAY=:1 openbox &' user
share|improve this answer
It's possible if 'startx' is allowed to be launched as unprivileged user. Otherwise, it gives "X: user not authorized to run the X server, aborting." – kolypto Jan 5 '11 at 16:17
@o_O: My system (Arch Linux) appears to have /usr/bin/Xorg setuid-root. – grawity Jan 5 '11 at 16:23
up vote 2 down vote accepted

It seems to be that the only way is to create temporary .xinitrc file. Here's the script:

#!/usr/bin/env bash

let xdisplay=${DISPLAY:1}+1

# Temporary xinitrc
temp_xinit="$(tempfile -p '.xinit' -s 'rc')" || exit
trap "rm -f -- '$temp_xinit'" EXIT

# Launch X
echo "sudo -u $username $@" > "$temp_xinit"
sudo xinit "$temp_xinit" -- :$xdisplay

Example usage:

$ /usr/local/games/braid [..options...]
share|improve this answer
It would be better to use mktemp, part of coreutils, instead of tempfile. – grawity Jan 6 '11 at 17:15

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.