I wrote a simple bash script that makes a backup of the home directory, e puts it into /var/backups. Since that directory is protected, I wrote the script as root, and then set the SUID.
armando@ubuntu:~/scripts/bash $ ll
-rwsr-xr-x 1 root root 2596 Jul 28 10:43 homebackup.sh*
Even so, I get the "Permission Denied" error when the scripts tries to write into /var/backups. Why?
In Linux and most other modern UNIX-family systems, setuid bits are only recognized for direct binary executables, not scripts.
This is by design, and for security reasons. You can work around it by building a compiled wrapper for your setuid scripts, or using an existing tool (such as sudo
with a configuration to avoid needing a password when calling the specific script as the desired user).