setuid and setuid bits on Unix files/directories

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. So if you have the following setuid file:

-rwsr-xr-x  1 tot        2437 Sep  8 18:12 foo

This means, that when any user executes this file ‘foo’, he will inherit tot's uid (which means he inherits all their file access permissions whether you're tot or not). Note: this can be quite dangerous. If you have a setuid shell owned by yourself, and I execute it, I essentially inherit your file permissions, hence have the ability to remove all your files.

In the above output, the reason for the small s means there's an x (execute) under it that's hidden. If it were a large S as in:

-rwSrw-rw-  1 tot        2437 Sep  8 18:12 foo

This means there's no x under the S. In order to make a file setuid, you prepend the three digits given chown with a 4, or use the s option. For example to get the first output:

-rwsr-xr-x  1 tot        2437 Sep  8 18:12 foo

I did a chmod 4755. The same is true for group, except use a 2 instead. If you want both, add them, to get 6. Hence a file with chmod 6755 would look like:

-rwsr-sr-x  1 tot        2437 Sep  8 18:12 foo

Again, notice the small s. What does that mean?

See Also Here

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License