This question already has an answer here:

I am learning about setuid and setgid where the user executing the script will inherit the owner's permission while running the script. To test this, I created a bash as user fiverr in /home/fiverr/test.sh with permision 4755.

rwsr-xr-x 1 fiverr fiverr 39 Dec  6 13:47 /home/fiverr/test.sh

It contains the following:

touch /home/fiverr/raza.txt

I logged-in as me (raza) and try to execute it but I get permission denied. How come?

touch: cannot touch ‘/home/fiverr/raza.txt’: Permission denied

marked as duplicate by Gilles, Sparhawk, slm Dec 7 '15 at 3:28

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


Trying to setuid a bash script won't work because of security measures. In the past setuid/setgid functionality was so abused to escalate privileges that nowadays there are several restrictions, including the bash binary and in extension bash scripts not inheriting/giving up setuid/setgid privileges, and only root being able to create setuid files in modern linux distributions.

If you want to run it, you have to get setuid before either using a binary wrapper compiled in C, or doing it in a binary altogether.

If in Debian, you can setuid a copy of /bin/dash and invoke what you want from there.

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