Question

I'm writing a shell script that is supposed to be run by users only in sudo user list, what's the appropriate way of doing this?

what I'm thinking is in the shell script, try to create a dummy file in system dir such as /var/run/ and remove it, so users not in sudo list will receive a permission error, but I believe there gotta be a more appropriate way of doing this, thanks for helping

Was it helpful?

Solution

You can check the values of $UID and $EUID in your script. They would be zero for being equivalent to root. Or, if not Bash, you can use id -u.

OTHER TIPS

Change the execute permissions on the script to only be executable by the user, and change the ownership of the script to root. That should do it.

make sure you are in the sudoers list then:

sudo chmod 700 /path/to/scriptname

[answering comment]
sorry - I don't use subversion: my guess is that you will need to run another script as a sudoer that will create the script with the correct permissions.

No, you do not have to change ownership to root, but it will keep things clean if you do.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top