简体   繁体   中英

Startup script run as a specific user Ubuntu

So I have a user, userA on Ubuntu. When the machine starts I want to add a script to /etc/rc0.d called startService

From inside of this script it will start several services using three scripts

startServiceA.sh
startServiceB.sh
startServiceC.sh

I'd like those three scripts to be started from userA, not root. How would I achieve this?

You can use commands like: su, sudo, runuser

Be sure to check the man pages.

This site might be able to help you also http://www.cyberciti.biz/open-source/command-line-hacks/linux-run-command-as-different-user/

You can run commands inside your startup script with:

sudo -u <username> ....

Note: you will need to to preface every command in the file that you want to run as another user. I'd recommend making a variable at the top of your script like so:

SUDO="sudo -u <username>"

Then just do: $SUDO <command>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM