Question

I wrote a small bash script to test suid permission

$ cat phone.sh
#!/bin/sh
echo "abc" >> out.txt

$ ls -l out.txt phone.sh
-rw-r--r-- root wzj      ...         out.txt
-rwsr-xr-x root wzj      ...         phone.sh

$ ./phone.sh
./phone.sh: 2: cannot create out.txt: Permission denied

why? I thought I already set the suid permission , so i can run the phone.sh with root privilege to modify the out.txt file , but i just failed. Can anybody tell me where i did wrong please?

Was it helpful?

Solution

Most *nix OSes don't allow scripts to utilize SUID. Check out Vidar's blog entry on the subject. Perl scripts can use SUID, but as Vidar explains, it's due to how Perl is implemented. It appears Bash scripts simply won't run with SUID. Sorry I don't have a more useful answer for you, it looks like this is just "how things are".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top