-1

Suppose i have two files

total 8
-r-sr-xr-x 1 root root 34 Oct  8 17:36 openroot.sh
-rwx------ 1 root root 38 Oct  8 17:34 root.txt

Content in root.txt :

Hi I am root file.

Content in openroot.sh :

#!/bin/bash

whoami cat root.txt

And now i am regular user (for example : person1). I execute command below:

./openroot.sh

The output is below :

person1
cat: root.txt: Permission denied

which means i cannot open root.txt. How does it happen?

Zozzizzez
  • 497

1 Answers1

1

For security reasons Linux ignores the SUID bit for shell scripts. See for example http://www.faqs.org/faqs/unix-faq/faq/part4/section-7.html for some reasons.

So your shell script doesn't run as root and isn't allowed to open the text file.