Here is the code:
(root:)
# mkdir /test
# cp /bin/bash /test/sbash
# chmod a+s /test/sbash
(user1:)
$ cd /test
$ ./sbash
$ mkdir trycreate
mkdir: cannot create directory `trycreate': Permission denied
And bash scripts with setuid bit set not work, either.
By the way, my setuid perl script works:
test.pl: (with setuid bit set, owner=root)
#!/usr/bin/perl
mkdir('/test/tryperlcreate') or die 'failed';
execute test.pl by user1 will create the directory owned by root.
You cannot make scripts SUID. Fortunately.
You may be interested in the SUID-wrapper program here, though: http://isptools.sourceforge.net/suid-wrap.html
I should also add, please please please make sure that you really need to do this before you do it. SUID binaries can be a great big gaping hole in your system.
I could repost what's been done to death already, but this is a great read.
Basically setuid shell scripts don't work by default
http://www.faqs.org/faqs/unix-faq/faq/part4/section-7.html
Try exec ./sbash with -p.
This is by design, in Ubuntu as well as in many other modern *nix system. While a setuid is always a potential security vulnerability this is extra so when dealing with shell scripts.
(The classic problem is having someone fool around with what is considered separate arguments by modifying the IFS environment variable.)
As others have mentioned, this is by design.
Try using sudo rather than setuid scripts.