I need to run a script as root
. The instructions given in the link say that I ought to:
- Set the SETUID bit on the script (i.e.
chmod 4755
). - Run the script as sudo (i.e.
sudo /path/to/thescript.sh
)
From the documentation I'm reading about the SETUID bit, my understanding is that by setting it, whoever runs the script is given the privileges of the owner. So if the owner of the script is root
, then anyone running the script with the SETUID bit on will have the script running with root privileges.
If that's the case, why do I need to do a sudo
before running the script if the SETUID bit is set?
If I need to use sudo
to run the script, why bother setting the SETUID bit. Just as an experiment I ran my script just using sudo
and it was able to do what I needed to do (the script recursively changes permissions on a bunch of files).