LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 01-03-2007, 07:54 AM   #1
Loonyjuice
LQ Newbie
 
Registered: Nov 2006
Posts: 2

Rep: Reputation: 0
Question Starting processes as a specific user?


I've got a script which needs to be run on system startup, as a specific user. As I understand, to start something automatically I can add it to /etc/rc.d/rc.local, but this will start up as root, correct?

Thanks in advance

M
 
Old 01-03-2007, 08:10 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,384

Rep: Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963
it will by default, but you can do something like "su -l myotherusername -c command" and it should run. of course, if it's a program which does not fork nicely (i.e. a daemon) then it'll hang the boot at that stage while it's running.
 
Old 01-03-2007, 08:11 AM   #3
b0uncer
Guru
 
Registered: Aug 2003
Distribution: CentOS, OS X
Posts: 5,131

Rep: Reputation: Disabled
You could just as well create a script which you run from ("call from") rc.local; the script would be like
Code:
#!/bin/bash
su preferred_username
commands, other stuff that is to be run as the other user
I guess that should work. su is normally used to become the super user (root), but it can be used to become another user too, but then the password for that user is needed or you will need to be root. I haven't tested if it works creating that kind of script and then make it executable and make rc.local run it (at boot), but logically it should. Try out; write a script like the above, where in the beginning you use su to become another user and then the command(s) you want to run, then make the script file executable using chmod +x scriptfilename and type the full path to the script in /etc/rc.local.
 
Old 01-03-2007, 08:19 AM   #4
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,384

Rep: Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963
no, that won't work, the su command spawns a login shell, and just sits there. it won't process the other commands as the new user. only when that su terminates is the rest of the script executed:

Code:
[root@server scripts]# su ac-phillipc; whoami
[guest@server scripts]$ exit
exit
root
[root@server scripts]#
 
Old 01-03-2007, 10:30 AM   #5
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
Another solution would be to write the commands (to be executed as the non-root user) in a script
and then to:
Code:
chown your_user:some_group the_script
chmod u+s the_script
Call that as from rc.local, and it should run under the specified user (see chown).
 
Old 01-03-2007, 01:49 PM   #6
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,384

Rep: Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963
hmm yes, that's an idea. depends how many comamnds you need, wouldn't be worth it for a single lline, but anythign lareger and it could easily be useful.
 
Old 01-04-2007, 02:17 AM   #7
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
For the one-liner, the -c option to su can easily be used, no?
 
  


Reply


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
FC4 hangs after starting all processes manjushp Fedora 3 01-15-2006 08:22 PM
starting processes on startup Henster Linux - Newbie 2 06-28-2005 12:12 PM
Many processes are starting in Linux r_213 Linux - Networking 6 11-18-2004 01:22 PM
How do I see what processes are touching specific devices ravalox Linux - Software 1 02-28-2004 08:35 PM
Starting Processes baldurkn Linux - Newbie 2 06-28-2003 07:08 PM


All times are GMT -5. The time now is 07:30 PM.

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