문제

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?

도움이 되었습니까?

해결책

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".

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top