Skip to content

Commit 72f3a52

Browse files
authored
Merge pull request #29 from Cipher7/master
Added topic Linux File Permissions - Closes issue #8 .
2 parents 5963f84 + 90f6e51 commit 72f3a52

File tree

1 file changed

+111
-4
lines changed

1 file changed

+111
-4
lines changed

linux-1/linux-basics.md

+111-4
Original file line numberDiff line numberDiff line change
@@ -307,10 +307,117 @@ cat > $fileName
307307

308308
> TODO: Add more information about Linux file permissions \(both `octal` and `ugo-rwx` formats\); Add information about `chmod` and `chown` commands; Add descriptions and examples \(issue [\#8](https://github.com/zweilosec/Infosec-Notes/issues/8)\)
309309
310-
`chmod -ugo -rwx -7777 5KFB6`
310+
File permissions in linux can be expressed in two formats, the rwx and the octal notation.
311+
312+
#### rwx notation
313+
314+
r = read\
315+
w = write\
316+
x = execute
317+
318+
In linux the if the permission of a file would be :
319+
320+
`-rwxrwxrwx`
321+
322+
Then that would mean that the anyone can read, write and execute the file. Breaking down this format into four parts :
323+
1. The first character would tell if it is a file or a directory, if it is a '-' (hyphen) then it would mean it is a file, but if it is 'd', then
324+
it would mean that it is a directory.
325+
2. The next three characters specify the permission of the owner of the file.
326+
3. The next three character specify the permissions of the group.
327+
4. The last three character would specify the characters of others.
328+
329+
In the above example all of them had rwx assigned to them, hence anyone could read, write and execute this file.
330+
331+
#### Octal notation
332+
333+
In the octal notation, the permissions are assigned using octal digits.
334+
335+
| Permissions | binary notation | octal notation | Description |
336+
| :--- | :--- | :--- | :-- |
337+
| --- | 000 | 0 | No permission |
338+
| --x | 001 | 1 | Execute permission only |
339+
| -w- | 010 | 2 | Write permission only |
340+
| -wx | 011 | 3 | Write and execute |
341+
| r-- | 100 | 4 | Read permission only |
342+
| r-x | 101 | 5 | Read and execute permission |
343+
| rw- | 110 | 6 | Read and write permission |
344+
| rwx | 111 | 7 | Read, write and execute |
345+
346+
From the above table we can easily derive :
347+
348+
Read = 4\
349+
Write = 2\
350+
Execute = 1
351+
352+
Therefore if you would want to give a read and write, it would be 6 (4+2=6).
353+
354+
Now taking the same above example of -rwxrwxrwx :
355+
In order to assign a file this permission using the octal notation and chmod
356+
it would be :
357+
358+
`chmod 777 file`
359+
360+
The first 7 would mean for the owner (4+2+1), the second 7 for the group and the third one for others.
361+
362+
u = user\
363+
g = group\
364+
o = others\
365+
a = u+g+o (all)
366+
367+
You can also give permissions using this method :
368+
369+
`chmod a+w file`
370+
371+
The above example would give write permissions to everyone.
372+
373+
`chmod a-x file`
374+
375+
The above example would remove execute permissions for everyone.
376+
377+
#### Advanced permissions
378+
379+
Other than just read and write, you can also set some other permissions like SUID and GUID.
380+
381+
`chmod 4000 file`
382+
383+
`chmod +s file`
384+
385+
Both the above examples would add the setuid bit to the file.
386+
387+
`chmod 2000 file`
388+
389+
`chmod +g file`
390+
391+
Both the above examples would add the getuid bit to the file
392+
393+
The sticky bit is added to folders mainly in order to prevent anyone else from deleting the folder.
394+
or any of it's contents. It is represented by a 't' at the end. When a sticky bit is set, nobody other than
395+
the owner or the root can delete the folder or the file.
396+
397+
`chmod 1000 folder`
398+
399+
`chmod +t folder`
400+
401+
Both the above examples set the sticky bit to the folders
402+
403+
Examples:
404+
`chmod 1744 file`
405+
406+
This would set the sticky bit, give all permissions to the owner and only read permission to the group and others
407+
408+
`chmod 0600 file`
409+
410+
This would only give the owner read and write permission, but not execute permission.
411+
412+
#### chown command
413+
414+
The chown command can be used to change the owner of a file or a directory.
311415

312416
`chown $user $group $file`
313417

418+
The above command would change the owner of the file from root to $user and also the group to $group
419+
420+
314421
### File compression and encryption
315422

316423
| Command | Description |
@@ -345,7 +452,7 @@ TODO: add more information about Managing connections in Linux \(Issue [\#9](htt
345452

346453
* Add commands such as telnet, SSH, nc, curl, wget
347454
* Add commands for listing information about open network connections: lsof -i, ss, netstat
348-
* include description and examples
455+
* include description and examples
349456

350457
| Command | Description |
351458
| :--- | :--- |
@@ -467,9 +574,9 @@ Delete script from default autorun: `update-rc.d -f </path/to/the/script> remove
467574

468575
On Windows \(easiest way!\):
469576

470-
1. Download and run [Rufus](https://rufus.ie/).
577+
1. Download and run [Rufus](https://rufus.ie/).
471578
2. Select the USB device and ISO you want to use, giving the volume a name if you wish.
472-
3. If you want to use persistence,
579+
3. If you want to use persistence,
473580
1. Click "Show advanced drive options".
474581
2. Select the amount of storage to use for persistence.
475582
4. Click "Start" and wait for it to finish.

0 commit comments

Comments
 (0)