I'm using Linux. On machine A I have such NFS setting in etc/exports:


I mount this directory on machine A on /home/nfs/ on machine B. And I've set setuid using chmod u+x program1.sh.

On machine B I want user xyz to run the program1.sh using root privilege. The setting of program1.sh is like below:

-rwsr-x--- 1 root house 1299 May 15 23:54 program1.sh

, which contains mkdir -p /home/nfs/house/nsx/

I set xyz to be in the group house so that xyz can run program1.sh. However when running program1.sh, it shows:

mkdir: cannot create directory `/home/nfs/house/nsx/': Permission denied

Running program1.sh as root is OK. I don't know why it's not working with user xyz.

migrated from stackoverflow.com May 19 '14 at 7:14

This question came from our site for professional and enthusiast programmers.


From the name program.sh, I am guessing that you're trying to run an interpreted script, not an ELF binary. Linux has ignored the setuid bit on scripts since long ago, due to possible security issues (race condition between kernel checking the +s bit, and script interpreter opening the file).

If this script needs to be available to specific users, create a sudo rule in /etc/sudoers that allows this:

xyz ALL=(root:root) NOPASSWD: /usr/local/bin/program.sh

There might be other solutions. For example, if you want to create home directories automatically (upon first login), the pam_mkhomedir.so PAM module exists for this.


Because only root and user nfs have permissions on files/folders under: /home/nfs

  • I've set setuid using chmod u+x. Isn't this mean I can run this program as root. Like passwd, its privilege is -rwsr-xr-x so other users can run that as root. – Marcus Thornton May 19 '14 at 6:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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