Execute a service with specific user - Ubuntu / CentOS

868 views Asked by At

I trying to execute a service and pass a specific user without run sudo command.

If I use the sudo command, the application will create a temp files with root permission and when the service was been restarted with correct user (Application User) the application user will not able to access this temp files.

Independent of the user who starts this service, the process need start with application user.

Have any way to fix it?

My OS it is Ubuntu 16 and CentOS 6/7.

Thanks

1

There are 1 answers

0
General Foch On

put the start command in sudo and use the su - c applicationuser /full/path/to/app and args

su -c NAME will run the following command as if called by NAME

you can clean that up a bit by putting the command in a shell script and then putting the shell script in sudo.