1

This question already has an answer here:

When I execute a script that uses the "mount" command, I need to enter my sudo password. However, I can launch a file explorer like nautilus and mount a filesystem from that application, without ever having to enter a password. What is the mechanism that allows some programs to execute commands that normally require root privilege?

My first instinct was that it is suid, but I changed the owner of a script to root and set the suid flag, i.e., "chmod 4777", but still I cannot perform things in the script that require root privilege.

marked as duplicate by Thomas Dickey, Archemar, roaima, slm Nov 20 '15 at 13:42

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

0

Despite the fact that suid shell scripts are always seen as a security risk, you need to specifc the -p shell flag to prevent the shell from restoring the uid to the real uid.

So you should add:

#!/bin/sh -p

to the beginning of your script

Not the answer you're looking for? Browse other questions tagged or ask your own question.