You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: file-permissions.md
+39-22
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,7 @@ Specified by POSIX.
7
7
Three types of people:
8
8
9
9
- 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.
11
11
- others: applies to all others who are not owner or in the group.
12
12
13
13
6 types of permissions:
@@ -16,21 +16,25 @@ Three types of people:
16
16
- write
17
17
- execute
18
18
- sticky bit
19
-
-sgid
20
-
-suid
19
+
-SGID
20
+
-SUID
21
21
22
22
#Notations
23
23
24
24
Two standard notation types: symbolic and numeric.
25
25
26
26
##Numeric
27
27
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
29
33
30
34
Meanings:
31
35
32
-
-`4000`: suid
33
-
-`2000`: sgid
36
+
-`4000`: SUID
37
+
-`2000`: SGID
34
38
-`1000`: sticky bit
35
39
-`0400`: owner read
36
40
-`0200`: write
@@ -42,6 +46,21 @@ Meanings:
42
46
-`0002`: write
43
47
-`0001`: exec
44
48
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
+
45
64
##Symbolic
46
65
47
66
Sample:
@@ -57,8 +76,8 @@ Meaning of each:
57
76
-`-`: regular file
58
77
-`d`: dir
59
78
-`l`: symlink (not for hardlink)
60
-
-`p`: named pipe (fifo)
61
-
-`s`: unix socket
79
+
-`p`: named pipe (FIFO)
80
+
-`s`: Unix socket
62
81
-`c`: character file
63
82
-`d`: block device file
64
83
@@ -74,13 +93,13 @@ Meaning of each:
74
93
75
94
-`4`
76
95
77
-
-`x`: owner can execute. suid off
96
+
-`x`: owner can execute. SUID off
78
97
-`s`: can . on
79
-
-`S`: cannot . suid on
98
+
-`S`: cannot . SUID on
80
99
81
100
-`567`
82
101
83
-
Same as `234`, with `7` as `4` but for sgid.
102
+
Same as `234`, with `7` as `4` but for SGID.
84
103
85
104
-`8`, `9`
86
105
@@ -142,10 +161,8 @@ Works even if `r` is off.
142
161
143
162
If you also have execute permissions to all of the parent dirs then you can:
144
163
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)
147
165
- access items in dir if their permissions let also you, for example modify file data.
148
-
149
166
- modify item list (add rename remove) *if w bit is also on*
150
167
151
168
The above can be done even if `r` is off.
@@ -176,11 +193,11 @@ They can however create files.
176
193
rm a/a
177
194
#removed
178
195
179
-
##Sgid
196
+
##SGID
180
197
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.
182
199
183
-
Dirs created under sgid also have sgid set!
200
+
Dirs created under SGID also have SGID set!
184
201
185
202
a=
186
203
b=
@@ -189,7 +206,7 @@ Dirs created under sgid also have sgid set!
189
206
gb=`id -gn "$b"`
190
207
su "$a"
191
208
192
-
Without sgid:
209
+
Without SGID:
193
210
194
211
mkdir not-sgid
195
212
chmod 777 not-sgid
@@ -205,7 +222,7 @@ Without sgid:
205
222
test -g not-sgid/d && echo g
206
223
207
224
208
-
With sgid
225
+
With SGID
209
226
210
227
mkdir sgid
211
228
chmod 2777 sgid
@@ -224,20 +241,20 @@ With sgid
224
241
225
242
###Application
226
243
227
-
You want many users to colaborate under a single dir.
244
+
You want many users to collaborate under a single dir.
228
245
229
246
You:
230
247
231
248
- create a group for collaboration
232
249
- create the dir with sticky bit
233
250
- add every user to the group
234
-
- make everyone give rwx on files they create
251
+
- make everyone give `rwx` on files they create
235
252
236
253
This way, only the group can work under the dir, and they all can access each other's files
237
254
238
255
#Files
239
256
240
-
##suid and sgid
257
+
##SUID and SGID
241
258
242
259
Does not work properly on scripts: you *must* have an executable:
0 commit comments