Cheatsheet Unix Bestandspermissies
Als je met Magento werkt in een Linux omgeving heb je enige kennis nodig van Unix bestandspermissies. Deze zijn al uitgebreid gedocumenteerd, maar ik wilde graag een eenvoudig en compleet overzicht dat setuid, setgid en het sticky bit omvatte. Omdat ik dit niet kon vinden besloot ik zelf een cheatsheet te maken.
Omdat dit een naslagpagina is, begin ik met de referentietabellen. Ik toon één permissie per regel, in het rood. Gevolgd door het chmod commando om het te produceren, een veelgebruikte naam, en een beschrijving in het Engels omdat de betekenis daarmee kort en krachtig is uit te drukken.
Read this article in English.
–rwx rwx rwx | chmod u+r | This file is readable by its owner. | |
-rwx rwx rwx | chmod u+w | This file is writable by its owner. | |
-rwx rwx rwx | chmod u+x | This file is executable by its owner. | |
-rws rwx rwx | chmod u+s | “setuid” | When the file is executed, the process assumes the id of the owner. |
-rwS rwx rwx | chmod u+s,u-x | When the file is executed, the process assumes the id of the owner, yet the owner may not execute it himself. | |
-rwx rwx rwx | chmod g+r | This file is readable by group members. | |
-rwx rwx rwx | chmod g+w | This file is writable by group members. | |
-rwx rwx rwx | chmod g+x | This file is executable by group members. | |
-rwx rws rwx | chmod g+s | “setgid” | When the file is executed, the process assumes the id of the group. |
-rwx rwS rwx | chmod g+s,g-x | When the file is executed, the process assumes the id of the group, yet no member of the group may execute it. | |
-rwx rwx rwx | chmod o+r | This file is readable by others. | |
-rwx rwx rwx | chmod o+w | This file is writable by others. | |
-rwx rwx rwx | chmod o+x | This file is executable by others. | |
-rwx rwx rwt | chmod o+t | “sticky bit” | Obsolete, originally used to keep the program in virtual memory for faster loading. |
-rwx rwx rwT | chmod o+t,o-x | Obsolete; not executable by others. |
drwx rwx rwx | chmod u+r | The owner of this directory may read the names of the files and directories in this directory. | |
drwx rwx rwx | chmod u+w | The owner of this directory may create, delete and rename files and directories in this directory. | |
drwx rwx rwx | chmod u+x | The owner of this directory may read data and metadata of files and directories in this directory. | |
drws rwx rwx | chmod u+s | “setuid” | No effect. |
drwS rwx rwx | chmod u+s,u-x | No effect. | |
drwx rwx rwx | chmod g+r | The names of the files and directories in this directory are readable by group members. | |
drwx rwx rwx | chmod g+w | Group members may create, delete and rename files and directories in this directory. | |
drwx rwx rwx | chmod g+x | Group members may read data and metadata of files and directories in this directory. | |
drwx rws rwx | chmod g+s | “setgid” | New files and directories in this directory inherit the the group id of the directory. |
drwx rwS rwx | chmod g+s,g-x | New files and directories in this directory inherit the the group id of the directory. Group members may not read data and metadata of files in this directory. | |
drwx rwx rwx | chmod o+r | Others may read the names of the files and directories in this directory. | |
drwx rwx rwx | chmod o+w | Others may create, delete and rename files and directories in this directory. | |
drwx rwx rwx | chmod o+x | Others may read data and metadata of files and directories in this directory. | |
drwx rwx rwt | chmod o+t | “restricted deletion flag” | A file or directory in this directory may only be deleted by its owner (, the directory owner and the superuser). |
drwx rwx rwT | chmod o+t,o-x | A file or directory in this directory may only be deleted by its owner (, the directory owner and the superuser). Others may not read data and metadata of files in this directory. |
Over de cheatsheet
Als je ls -l
uitvoert, zie je een lijst met de bestanden in de directory. Het toont het bestandstype, de bestandspermissies, de eigenaar en de groep.
ls -l
Hier is een voorbeeld van een regel uit het resultaat
-rw-rw-r– 1 patrick www-data 7 feb 20 11:41 hello.txt
-rw-rw-r– zijn de bestandspermissies, patrick is de eigenaar van het bestand, en www-data is groep van het bestand.
Bestandspermissies zijn als volgt gegroepeerd:
–rwx rwx rwx | Eigenaar |
-rwx rwx rwx | Groep |
-rwx rwx rwx | Anderen |
Je kunt de bestandspermissies wijzigen met het chmod commando. Bijvoorbeeld
chmod +x bin/magento | Maakt een bestand uitvoerbaar, voor de eigenaar, de groep and anderen (iedereen). |
chmod g+s pub/media | Zorgt ervoor dat nieuwe bestanden en directories in pub/media de group id van de directory overerven. |
Referenties
http://unix.stackexchange.com/questions/79395/how-does-the-sticky-bit-work
https://en.wikipedia.org/wiki/File_system_permissions
https://linux.die.net/man/1/chmod
https://en.wikipedia.org/wiki/Setuid