LinuxAnswers - the LQ Linux tutorial section.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


Search this Thread
Old 03-17-2007, 01:58 PM   #1
Amigo developer
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,780

Rep: Reputation: 482Reputation: 482Reputation: 482Reputation: 482Reputation: 482
Start a program for a user as root, with process belonging to user

I'm trying to to start a process while running as root. But I want the program to run on a users desktop and have the process belong to the user and not root.

I've been doing something like this:
sudo $USER
xauth merge /home/$USER/.Xauthority
export DISPLAY=:0.0
/usr/bin/myprogram &

this will start the program alright, but the process belongs to root and not to $USER. How do I get this process to be owned by the $USER?
Old 03-17-2007, 03:36 PM   #2
LQ Newbie
Registered: Mar 2006
Location: LitH, IL
Distribution: Ubuntu Feisty
Posts: 6

Rep: Reputation: 0

sudo -u $USER [command]
Old 03-17-2007, 04:29 PM   #3
Registered: Jan 2006
Location: Romania
Distribution: Suse 12.0, Slackware 12.1, Debian, Ubuntu, Gentoo
Posts: 301

Rep: Reputation: 30
or maybe

su $USER

this should run all the commands that follow as the user stored in the variable
Old 03-19-2007, 06:09 AM   #4
Amigo developer
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,780

Original Poster
Rep: Reputation: 482Reputation: 482Reputation: 482Reputation: 482Reputation: 482
Neither of those will work.
The user is logged in and running X. I am running a shell script as root which I want to start a GUI application on the users desktop, but the process should belong to the user.
Old 03-19-2007, 02:58 PM   #5
Senior Member
Registered: Nov 2005
Distribution: Debian
Posts: 2,555

Rep: Reputation: 883Reputation: 883Reputation: 883Reputation: 883Reputation: 883Reputation: 883Reputation: 883
You have to put them inside the shell script:

xauth merge /home/$USER/.Xauthority
export DISPLAY=:0.0
su $USER -c '/usr/bin/myprogram' &


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
C program to see user log on in system and print user with real user name also naveen245 Programming 2 12-21-2005 01:53 AM
Boot process as non-root user fatman Debian 6 06-07-2005 05:08 PM
start a X program as different user, how? IamDaniel Linux - General 1 01-31-2005 12:46 AM
I can start X with root but not with another user pewillette Linux - Newbie 4 04-21-2004 07:58 PM
Getting a program to start with root privileges when a user logs in. joeking Linux - Security 4 10-24-2003 12:47 PM

All times are GMT -5. The time now is 11:58 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration