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 :)

link|improve this question

feedback

2 Answers

Try

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

Edit: Also try running

X :1 &
su -c 'DISPLAY=:1 openbox &' user
link|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." – o_O Tync 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
feedback
up vote 0 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

username="$USER"
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:

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

Your Answer

 
or
required, but never shown

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