Starting a service as a different user

Support for security such as Firewalls and securing linux
Post Reply
jordend
Posts: 3
Joined: 2015/11/04 16:18:49

Starting a service as a different user

Post by jordend » 2015/11/04 16:22:01

Hi,

I have my CentOS box running a backup server and I want it to automatically run two services at startup as a specific user. Any help with this would be greatly appreciated. Thanks!

aks
Posts: 2859
Joined: 2014/09/20 11:22:14

Re: Starting a service as a different user

Post by aks » 2015/11/04 17:44:57

Depends on the program(s) involved. You should really look at using systemd, but that too depends on the programs and how they behave.

From the shell (so a script too), you could use su <user> -c "<commands_to_run> > <log_file> 2>&1 " &

jordend
Posts: 3
Joined: 2015/11/04 16:18:49

Re: Starting a service as a different user

Post by jordend » 2015/11/04 17:46:35

Where would I put that script for it to start that service at startup?

User avatar
TrevorH
Forum Moderator
Posts: 27125
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: Starting a service as a different user

Post by TrevorH » 2015/11/04 18:04:55

Systemd unit files should go in /etc/systemd/system and you can look in /usr/lib/systemd/system for examples of others that are already in use to find one similar to the things you want to do. I believe the correct thing to put in the unit file would be User=youruser
CentOS 6 will die in November 2020 - migrate sooner rather than later!
CentOS 5 has been EOL for nearly 3 years and should no longer be used for anything!
Full time Geek, part time moderator. Use the FAQ Luke

jordend
Posts: 3
Joined: 2015/11/04 16:18:49

Re: Starting a service as a different user

Post by jordend » 2015/11/04 21:50:47

Well, after all that, I found out from the vendor that this has to be ran as root. :/

aks
Posts: 2859
Joined: 2014/09/20 11:22:14

Re: Starting a service as a different user

Post by aks » 2015/11/05 18:52:36

That's not good :twisted:
Complain and tell them your giving them money for what amounts to the crappiest of crap....

Post Reply

Return to “CentOS 7 - Security Support”