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
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.