You are not logged in.

#1 2006-01-14 00:36:40

rayzorblayde
Member
Registered: 2004-01-04
Posts: 67

Starting a program on boot as a non-root user

Well, the title explains my question for the most part.  I'm trying to start a program when the computer boots as a non-root user, like apache uses the httpd user.  i tried searching on multiple subjects, but have not found anything that works.  could someone please help me out? thanks!


loading.... please wait....

Offline

#2 2006-01-14 04:58:52

stonecrest
Member
From: Boulder
Registered: 2005-01-22
Posts: 1,190

Re: Starting a program on boot as a non-root user

You could always use sudo to do it.


I am a gated community.

Offline

#3 2006-01-14 06:37:19

Cam
Member
From: Brisbane, Aus
Registered: 2004-12-21
Posts: 658
Website

Re: Starting a program on boot as a non-root user

su rayzor -c ./programname

Offline

#4 2006-01-14 07:02:46

codergeek42
Member
From: Anaheim, CA (USA)
Registered: 2005-06-03
Posts: 90
Website

Re: Starting a program on boot as a non-root user

rayzorblayde wrote:

Well, the title explains my question for the most part.  I'm trying to start a program when the computer boots as a non-root user, like apache uses the httpd user.  i tried searching on multiple subjects, but have not found anything that works.  could someone please help me out? thanks!

You don't want to run Apache as httpd. It needs the root priveleges to bind to port 80 (normal user processes are restricted to ports at 1024 and higher). Don't worry though! Once it binds properly and is listening for incoming HTTP requests, it will drop all root priveleges. smile

If you really want to though:

$ man su

Hope that helps!


~Peter~

Offline

#5 2006-01-14 16:37:27

rayzorblayde
Member
Registered: 2004-01-04
Posts: 67

Re: Starting a program on boot as a non-root user

Well,

the program's start script is weird, and requires me to 'cd' to the directory and then run the `./program start`.  i'm assuming the su with the -c flag could work on server bootup, but I want to get the command working manually first (ie. just using the su command from a shell before i try to put the command in something like rc.local or whatever).

edit: the -c flag wont' let me run more than one command, even with ';' between like you can in the shell.

i would have thought there would have been an easier way to start a program as another user on bootup...


loading.... please wait....

Offline

#6 2006-01-14 17:11:20

Cerebral
Forum Fellow
From: Waterloo, ON, CA
Registered: 2005-04-08
Posts: 3,108
Website

Re: Starting a program on boot as a non-root user

su rayzor -c "command 1 && command 2 && command 3"

should work, unless you're expecting one of the commands in the chain to fail.

Offline

#7 2006-01-20 22:48:55

hiower4
Member
Registered: 2004-07-31
Posts: 38

Re: Starting a program on boot as a non-root user

Note that using su to get right privileges doesn't automatically setup the environment, variables, paths etc.
The following way is the only which I have found to provide full functionality, i.e. the same behaviour as if I login.

/bin/su USER -l -c "/bin/bash --login -c COMMAND"

where command is whatever you want. I use it in /etc/inittab to start X automatically with, you can surely put it in rc.local
You can also try it out on the command line if you want  to.


#348498 +(4737)- [X]

<MasterG> .....................................................................
          ..................................
<judas> where's pacman when you need him?

Offline

#8 2006-01-20 23:00:36

Snarkout
Member
Registered: 2005-11-13
Posts: 542

Re: Starting a program on boot as a non-root user

Write an init script?  Seriously.


Unthinking respect for authority is the greatest enemy of truth.
-Albert Einstein

Offline

#9 2006-01-21 22:28:36

Arch
Member
Registered: 2005-11-05
Posts: 37

Re: Starting a program on boot as a non-root user

codergeek42 wrote:
rayzorblayde wrote:

Well, the title explains my question for the most part.  I'm trying to start a program when the computer boots as a non-root user, like apache uses the httpd user.  i tried searching on multiple subjects, but have not found anything that works.  could someone please help me out? thanks!

You don't want to run Apache as httpd. It needs the root priveleges to bind to port 80 (normal user processes are restricted to ports at 1024 and higher). Don't worry though! Once it binds properly and is listening for incoming HTTP requests, it will drop all root priveleges. smile

If you really want to though:

$ man su

Hope that helps!

Running Apache under root can be dangerous.  There was an instance on my webserver where I had a non-root account running Apache, yet some malicious internet user was able to have certain controls to the webserver (through some insecurities in Apache.)   Had I have Apache run as root, he/she would have TOTAL access to my server.


This signature just crossed the line.

Offline

#10 2006-01-22 00:38:02

codergeek42
Member
From: Anaheim, CA (USA)
Registered: 2005-06-03
Posts: 90
Website

Re: Starting a program on boot as a non-root user

Arch wrote:

Running Apache under root can be dangerous.  There was an instance on my webserver where I had a non-root account running Apache, yet some malicious internet user was able to have certain controls to the webserver (through some insecurities in Apache.)   Had I have Apache run as root, he/she would have TOTAL access to my server.

It seems as though you didn't even read what I wrote.

codergeek42 wrote:

You don't want to run Apache as httpd. It needs the root priveleges to bind to port 80 (normal user processes are restricted to ports at 1024 and higher). Don't worry though! Once it binds properly and is listening for incoming HTTP requests, it will drop all root priveleges. smile


~Peter~

Offline

#11 2006-01-22 17:54:49

Arch
Member
Registered: 2005-11-05
Posts: 37

Re: Starting a program on boot as a non-root user

No, I read what you wrote.

I wasn't disagreeing with you or construing what you said was wrong.  I was sharing my experience with something I had encountered (on a dedicated server that I'm renting) that was related to this subject.  My main point was that security is very important and shouldn't be overlooked, especially running a busy webserver.  And yes, I also agree with you on your previous statement; I also avoid running Apache under httpd.  A normal not-so-obvious account is used to run Apache in my case.  Hope that clarify things out.  smile


This signature just crossed the line.

Offline

#12 2006-01-22 20:20:16

pikass
Member
From: Schwartz space
Registered: 2005-11-28
Posts: 85

Re: Starting a program on boot as a non-root user

But running apache with just another user means no security enhancement. To put it into a (hardened) chroot prison would do.

Offline

Board footer

Powered by FluxBB