On Unix and workalikes such as Linux, the SetUID flag on an executable program tells the system to run the program with the privileges of the owner of the file, rather than the user account that runs it.

Take, for example, a backup program that needs permissions to access block devices (that's hard drives, to non-unix folk) directly; it would not be able to function when started by a regular user, who doesn't have block device permissions.

If the SetUID flag were set on this program, assuming the file was owned by root, then any user account could run it, and it would run as root, enabling any user to run backups.

The SetUID bit is usually disabled for shell scripts written in Perl, bash, or other scripting languages, due to the potential security holes it introduces.  Of course, that means if you've written a bash script to mount some device(s), run a backup, then unmount again, it won't run as root, even if owned by root and with the SetUID bit set.

A simple workaround for this is to write a simple C program, with the sole function of calling the script:

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>

int main()
{
    setuid( 0 );
    system( "/location/of/myscript.sh" );

    return 0;
}

Save it as myscript.c, then compile it with GCC, or some other compiler:

gcc myscript.c -o myscript

Put the resulting file into the system path - I prefer putting stuff like this into /usr/local/bin/ - so that any user can easily run it, set its owner to root, and set the SetUID flag.

Now, any user will be able to run myscript.sh as root, by running myscript.

The obvious downside of this is that result codes from myscript.sh become more difficult to pass back to a calling program, unless everything is running as root, which will not be desirable in some situations.  It can certainly be done, and it's really only a few more lines of code in myscript.c, but that's the topic for another post in future.