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.

Bestanden
rwx rwx rwxchmod u+rThis file is readable by its owner.
-rwx rwx rwxchmod u+wThis file is writable by its owner.
-rwx rwx rwxchmod u+xThis file is executable by its owner.
-rws rwx rwxchmod u+s“setuid”When the file is executed, the process assumes the id of the owner.
-rwS rwx rwxchmod u+s,u-xWhen the file is executed, the process assumes the id of the owner, yet the owner may not execute it himself.
-rwx rwx rwxchmod g+rThis file is readable by group members.
-rwx rwx rwxchmod g+wThis file is writable by group members.
-rwx rwx rwxchmod g+xThis file is executable by group members.
-rwx rws rwxchmod g+s“setgid”When the file is executed, the process assumes the id of the group.
-rwx rwS rwxchmod g+s,g-xWhen the file is executed, the process assumes the id of the group, yet no member of the group may execute it.
-rwx rwx rwxchmod o+rThis file is readable by others.
-rwx rwx rwxchmod o+wThis file is writable by others.
-rwx rwx rwxchmod o+xThis file is executable by others.
-rwx rwx rwtchmod o+t“sticky bit”Obsolete, originally used to keep the program in virtual memory for faster loading.
-rwx rwx rwTchmod o+t,o-xObsolete; not executable by others.
Directories
drwx rwx rwxchmod u+rThe owner of this directory may read the names of the files and directories in this directory.
drwx rwx rwxchmod u+wThe owner of this directory may create, delete and rename files and directories in this directory.
drwx rwx rwxchmod u+xThe owner of this directory may read data and metadata of files and directories in this directory.
drws rwx rwxchmod u+s“setuid”No effect.
drwS rwx rwxchmod u+s,u-xNo effect.
drwx rwx rwxchmod g+rThe names of the files and directories in this directory are readable by group members.
drwx rwx rwxchmod g+wGroup members may create, delete and rename files and directories in this directory.
drwx rwx rwxchmod g+xGroup members may read data and metadata of files and directories in this directory.
drwx rws rwxchmod g+s“setgid”New files and directories in this directory inherit the the group id of the directory.
drwx rwS rwxchmod g+s,g-xNew 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 rwxchmod o+rOthers may read the names of the files and directories in this directory.
drwx rwx rwxchmod o+wOthers may create, delete and rename files and directories in this directory.
drwx rwx rwxchmod o+xOthers may read data and metadata of files and directories in this directory.
drwx rwx rwtchmod 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 rwTchmod o+t,o-xA 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 rwxEigenaar
-rwx rwx rwxGroep
-rwx rwx rwxAnderen

Je kunt de bestandspermissies wijzigen met het chmod commando. Bijvoorbeeld

chmod +x bin/magentoMaakt een bestand uitvoerbaar, voor de eigenaar, de groep and anderen (iedereen).
chmod g+s pub/mediaZorgt 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

Geef een antwoord

Het e-mailadres wordt niet gepubliceerd.