I figured out how to read/convert the symbolic rwx parts to 421 octal parts, which was pretty straight forward. But I am extremely confused when there's the special characters involved. We know that -r-xr---wx converts to 0543, but what does -r-sr---wt or -r-xr---wt convert to?
I believe for under user execute permission there's x, s, S. For group execute permission there's also x, s, S. Then all other user execute permission there's x, t, T. What do all these mean and how are they converted over to the octal notation. I'm guessing it has something to do with the 0 position in 0421?
From my class notes it says that 5543 converts to -r-sr---wt. Then a sample question of -r-S-wsrw- converts to 6536 except that it wants us to fix the second position (5) so that it'll be the correct conversion.
I searched and Googled plenty, but surprisingly couldn't find anything on these special characters.
After in-depth searching on the Web, I found this link about Understanding Linux File Permissions which describes it in detail :
s - This indicated the setuid/setgid permissions. This is not set displayed in the special permission part of the permissions display, but is represented as a s in the read portion of the owner or group permissions.
t - This indicates the sticky bit permissions. This is not set displayed in the special permission part of the permissions display, but is represented as a t in the executable portion of the all users permissions
Setuid/Setgid Special Permissions
---The setuid/setguid permissions are used to tell the system to run an executable as the owner with the owner\'s permissions.
---Be careful using setuid/setgid bits in permissions. If you incorrectly assign permissions to a file owned by root with the setuid/setgid bit set, then you can open your system to intrusion.
---You can only assign the setuid/setgid bit by explicitly defining permissions. The character for the setuid/setguid bit is s.
Sticky Bit Special Permissions
---The sticky bit can be very useful in shared environment because when it has been assigned to the permissions on a directory it sets it so only file owner can rename or delete the said file.
---You can only assign the sticky bit by explicitly defining permissions. The character for the sticky bit is t.
Logic behind conversion from numeric(1/2/4421) to symbolic notation(rwx/s/t) :
EDIT :
The first number represents the Owner permission; the second represents the Group permissions; and the last number represents the permissions for all other users. The numbers are a binary representation of the rwx string.
r = 4
w = 2
x = 1
---> The sticky bit can be set using the chmod command and can be set using its octal mode 1000 or by its symbol t (s is already used by the setuid bit). For example, to add the bit on the directory /usr/local/tmp, one could type chmod 1777 /usr/local/tmp
.
---> The setuid and setgid bits are normally set with the command chmod by setting the high-order octal digit to 4 for setuid or 2 for setgid. chmod 6711 file
will set both the setuid and setgid bits (4+2=6), making the file read/write/executable for the owner (7), and executable by the group (first 1) and others (second 1).
s --- The setuid bit when found in the user triad; the setgid bit when found in the group
triad; it is not found in the others triad; it also implies that x is set.
S --- Same as s, but x is not set; rare on regular files, and useless on folders.
t --- The sticky bit; it can only be found in the others triad; it also implies that x is
set.
T --- Same as t, but x is not set; rare on regular files, and useless on folders.
s, S, t and T values are always appended before the user-group-others permission notation. So, first letter of the notation represents s, S, t or T values appended to the string. The next 3 letters are the usual permission.
Your questions/examples related to file-permissions :
1. -r-sr---wt = 5543, first 5(s set for user = 4 + t set for others = 1),
second 5(r=4,s=1), third 4(r = 4), and last, fourth 3(w=2, t = 1).
2. -r-S-wsrw- = 6436, first 6(S set for user = 4 + s set for group = 2),
second 5(r=4, x=0, since S don't account for x),
third 3(w = 2, s results in x = 1), and last, fourth 6(r=4,w=2).