0

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
  • 475
  • You don't have permission to it, your 'regular' user isn't root, and root owns that file (and there are NO permissions for other users as per your first paste) – guiverc Oct 08 '20 at 12:03
  • setuid only works for binary executables, it is ignored for all interpreted executables. like shell scripts. – Soren A Oct 08 '20 at 12:26

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.