Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

2 Answers 2

Try

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 1 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...]
share|improve this answer
1  
It would be better to use mktemp, part of coreutils, instead of tempfile. –  grawity Jan 6 '11 at 17:15

Your Answer

 
discard

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.