Skip to content

Commit b146ddb

Browse files
committed
Update SUID, file type permission bits.
1 parent 43d5618 commit b146ddb

File tree

1 file changed

+39
-22
lines changed

1 file changed

+39
-22
lines changed

file-permissions.md

+39-22
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Specified by POSIX.
77
Three types of people:
88

99
- owner: applies the person who created the file.
10-
- group: the main group of he person who created the file. applies to all people who are in that group.
10+
- group: the main group of he person who created the file. Applies to all people who are in that group.
1111
- others: applies to all others who are not owner or in the group.
1212

1313
6 types of permissions:
@@ -16,21 +16,25 @@ Three types of people:
1616
- write
1717
- execute
1818
- sticky bit
19-
- sgid
20-
- suid
19+
- SGID
20+
- SUID
2121

2222
#Notations
2323

2424
Two standard notation types: symbolic and numeric.
2525

2626
##Numeric
2727

28-
12 bits, logically grouped into 4 groups of three thus use of octal, since octal can represent 3 bits per digit)
28+
12 bits, logically grouped into 4 groups of three, thus the natural usage of octal notation, which can represent 3 bits per digit.
29+
30+
Explained at:
31+
32+
man stat
2933

3034
Meanings:
3135

32-
- `4000`: suid
33-
- `2000`: sgid
36+
- `4000`: SUID
37+
- `2000`: SGID
3438
- `1000`: sticky bit
3539
- `0400`: owner read
3640
- `0200`: write
@@ -42,6 +46,21 @@ Meanings:
4246
- `0002`: write
4347
- `0001`: exec
4448

49+
In Linux, the file type is also stored in the same `struct` as it's permissions. It is therefore also possible to show the file type (regular file, directory, symlink, device, etc.) in the same number that describes the permission by adding 6 more bits:
50+
51+
S_IFMT 0170000 bit mask for the file type bit fields
52+
S_IFSOCK 0140000 socket
53+
S_IFLNK 0120000 symbolic link
54+
S_IFREG 0100000 regular file
55+
S_IFBLK 0060000 block device
56+
S_IFDIR 0040000 directory
57+
S_IFCHR 0020000 character device
58+
S_IFIFO 0010000 FIFO
59+
60+
This also suggests why the symbolic notation also incorporates this information in a single word: because all that data is in the same place.
61+
62+
TODO: why the leading `0`?
63+
4564
##Symbolic
4665

4766
Sample:
@@ -57,8 +76,8 @@ Meaning of each:
5776
- `-`: regular file
5877
- `d`: dir
5978
- `l`: symlink (not for hardlink)
60-
- `p`: named pipe (fifo)
61-
- `s`: unix socket
79+
- `p`: named pipe (FIFO)
80+
- `s`: Unix socket
6281
- `c`: character file
6382
- `d`: block device file
6483

@@ -74,13 +93,13 @@ Meaning of each:
7493

7594
- `4`
7695

77-
- `x`: owner can execute. suid off
96+
- `x`: owner can execute. SUID off
7897
- `s`: can . on
79-
- `S`: cannot . suid on
98+
- `S`: cannot . SUID on
8099

81100
- `567`
82101

83-
Same as `234`, with `7` as `4` but for sgid.
102+
Same as `234`, with `7` as `4` but for SGID.
84103

85104
- `8`, `9`
86105

@@ -142,10 +161,8 @@ Works even if `r` is off.
142161

143162
If you also have execute permissions to all of the parent dirs then you can:
144163

145-
- cd into dir (every process has current dir informatio associated to it)
146-
164+
- `cd` into dir (every process has current dir information associated to it)
147165
- access items in dir if their permissions let also you, for example modify file data.
148-
149166
- modify item list (add rename remove) *if w bit is also on*
150167

151168
The above can be done even if `r` is off.
@@ -176,11 +193,11 @@ They can however create files.
176193
rm a/a
177194
#removed
178195

179-
##Sgid
196+
##SGID
180197

181-
Files created under sgid dir get the same group as the parent dir.
198+
Files created under SGID dir get the same group as the parent dir.
182199

183-
Dirs created under sgid also have sgid set!
200+
Dirs created under SGID also have SGID set!
184201

185202
a=
186203
b=
@@ -189,7 +206,7 @@ Dirs created under sgid also have sgid set!
189206
gb=`id -gn "$b"`
190207
su "$a"
191208

192-
Without sgid:
209+
Without SGID:
193210

194211
mkdir not-sgid
195212
chmod 777 not-sgid
@@ -205,7 +222,7 @@ Without sgid:
205222
test -g not-sgid/d && echo g
206223

207224

208-
With sgid
225+
With SGID
209226

210227
mkdir sgid
211228
chmod 2777 sgid
@@ -224,20 +241,20 @@ With sgid
224241

225242
###Application
226243

227-
You want many users to colaborate under a single dir.
244+
You want many users to collaborate under a single dir.
228245

229246
You:
230247

231248
- create a group for collaboration
232249
- create the dir with sticky bit
233250
- add every user to the group
234-
- make everyone give rwx on files they create
251+
- make everyone give `rwx` on files they create
235252

236253
This way, only the group can work under the dir, and they all can access each other's files
237254

238255
#Files
239256

240-
##suid and sgid
257+
##SUID and SGID
241258

242259
Does not work properly on scripts: you *must* have an executable:
243260

0 commit comments

Comments
 (0)