Best practice to run Linux service as a different user

James Brady :

Services default to starting as root at boot time on my RHEL box. If I recall correctly, the same is true for other Linux distros which use the init scripts in /etc/init.d.

What do you think is the best way to instead have the processes run as a (static) user of my choosing?

The only method I'd arrived at was to use something like:

 su my_user -c 'daemon my_cmd &>/dev/null &'

But this seems a bit untidy...

Is there some bit of magic tucked away that provides an easy mechanism to automatically start services as other, non-root users?

EDIT: I should have said that the processes I'm starting in this instance are either Python scripts or Java programs. I'd rather not write a native wrapper around them, so unfortunately I'm unable to call setuid() as Black suggests.

user3850 :

On Debian we use the start-stop-daemon utility, which handles pid-files, changing the user, putting the daemon into background and much more.

I'm not familiar with RedHat, but the daemon utility that you are already using (which is defined in /etc/init.d/functions, btw.) is mentioned everywhere as the equivalent to start-stop-daemon, so either it can also change the uid of your program, or the way you do it is already the correct one.

If you look around the net, there are several ready-made wrappers that you can use. Some may even be already packaged in RedHat. Have a look at daemonize, for example.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Azure: Service principal user best practice with Terraform

From Dev

Run a cmd from linux server as a different user

From Dev

Android - Best practice for a periodic service

From Dev

Best practice to detect if service is available

From Dev

Salesforce Integration User Best Practice

From Dev

Get an application to run as a different user from a windows service

From Dev

Run program (exe) as different user (service account), access to network share

From Dev

What is the best practice to manage user profile when using Huawei Auth Service

From Dev

What are "sufficient access rights to run the Nexus service" (as nexus user on Linux)

From Dev

*.service run as user

From

Best Practice for Updating AWS ECS Service Tasks

From Dev

Is it best Practice to Call Web API in Worker service?

From Java

Web service client design pattern (best practice)

From Dev

FOSUserBundle login with email with service Provider, best practice

From Dev

Best practice Symfony2 (Factory) Service

From Dev

Best practice for instant claim of a page by Service Worker

From Dev

Best practice to use config service in NestJS Module

From Dev

Best practice run a filesystem check on lvm volume?

From Dev

Run as different user and elevate

From Dev

Is sed run as a different user?

From Dev

Run playbook as a different user

From Dev

Run as a different user on a shortcut

From Dev

Ngrx effect dispatch different actions - best practice

From Dev

Best practice for calling two different endpoints for a widget?

From Dev

Best practice for assigning key for different widgets?

From Dev

What is best practice to implement SQS on different environments?

From Dev

Best practice for dynamically translating content into different languages

From Dev

Kubernetes best practice: different config for local or remote

From Dev

NodeJS Polling per User Structure best practice

Related Related

  1. 1

    Azure: Service principal user best practice with Terraform

  2. 2

    Run a cmd from linux server as a different user

  3. 3

    Android - Best practice for a periodic service

  4. 4

    Best practice to detect if service is available

  5. 5

    Salesforce Integration User Best Practice

  6. 6

    Get an application to run as a different user from a windows service

  7. 7

    Run program (exe) as different user (service account), access to network share

  8. 8

    What is the best practice to manage user profile when using Huawei Auth Service

  9. 9

    What are "sufficient access rights to run the Nexus service" (as nexus user on Linux)

  10. 10

    *.service run as user

  11. 11

    Best Practice for Updating AWS ECS Service Tasks

  12. 12

    Is it best Practice to Call Web API in Worker service?

  13. 13

    Web service client design pattern (best practice)

  14. 14

    FOSUserBundle login with email with service Provider, best practice

  15. 15

    Best practice Symfony2 (Factory) Service

  16. 16

    Best practice for instant claim of a page by Service Worker

  17. 17

    Best practice to use config service in NestJS Module

  18. 18

    Best practice run a filesystem check on lvm volume?

  19. 19

    Run as different user and elevate

  20. 20

    Is sed run as a different user?

  21. 21

    Run playbook as a different user

  22. 22

    Run as a different user on a shortcut

  23. 23

    Ngrx effect dispatch different actions - best practice

  24. 24

    Best practice for calling two different endpoints for a widget?

  25. 25

    Best practice for assigning key for different widgets?

  26. 26

    What is best practice to implement SQS on different environments?

  27. 27

    Best practice for dynamically translating content into different languages

  28. 28

    Kubernetes best practice: different config for local or remote

  29. 29

    NodeJS Polling per User Structure best practice

HotTag

Archive