0

let's say there are to users A and B, belong to different group. and bot of them are not root

first, as user A.

1) touch a.txt; echo "hello word" > a.txt
2)chmod 600
3) touch b
4) echo "cat a.txt" > b
5) chmod 4755 b

and then switch to user B, my assumption is user B can successfully run the binary and get the greeting "hello word", but when I actually run the binary as User B, I got "permission denied". so why?

Haiyuan Zhang
  • 40,802
  • 41
  • 107
  • 134
  • Do you mean `2)chmod 600 a.txt`? And, you should have given the complete error message, such as `cat: can't open 'a.txt': Permission denied`, since it can contain helpful information. – Armali May 08 '14 at 08:20

2 Answers2

1

Linux does not implement the handling of the S_ISUID bit of script files; instead, the mode bits of the interpreter (shell) are used.

Armali
  • 18,255
  • 14
  • 57
  • 171
0

The concept of setuid files means that if you have the setuid bit turned on on a file, anybody executing that command (file) will inherit the permissions of the owner of the file.

$ chmod 4755 b --verbose
mode of `b' changed to 4755 (rwsr-xr-x)

I suspect user A and B belong to seperate groups, so you need to do setgid also. This can be done by adding 2, for both setuid and setgid add to get 6.

$ chmod 6755 b --verbose
mode of `b' changed to 6755 (rwsr-sr-x)
manav m-n
  • 11,136
  • 23
  • 74
  • 97