Linux Permissions
check permissions with
sudo -lUnderstanding Permissions:Files and directories have permissions for three user classes: owner, group, and others.
Each class has three permission types: read, write, and execute.
Permissions are represented in two ways:
Symbolic notation (e.g.,
rwxr-xr-x)Octal notation (e.g.,
755)
Viewing Permissions:
Use the
ls -lcommand to list file details, including permissions.
Common Permissions:
r: Read permission allows viewing content.w: Write permission allows modifying content.x: Execute permission allows running the file as a program (for files).
Changing Permissions:
Use the
chmodcommand to change permissions.Symbolic notation:
+: Add permission.-: Remove permission.=: Set specific permission.
Octal notation:
Three digits represent permissions for owner, group, and others.
Each digit is the sum of permission values (4 for read, 2 for write, 1 for execute).
Ownership and Groups:
Use the
chowncommand to change file ownership.Use the
chgrpcommand to change file group.Use the
idcommand to find your user ID and group ID.
Common Commands:
Change file permissions:
Symbolic:
chmod ugo+r myfile.txt(add read to all)Octal:
chmod 644 myfile.txt(read/write for owner, read for group/others)
Change owner:
chown username:groupname myfile.txtChange group:
chgrp groupname myfile.txtShow current permissions:
ls -l myfile.txtSet default permissions:
umask 022(sets default to 644 for files)
Security Tips:
Use the most restrictive permissions necessary.
Avoid giving write access to unnecessary users.
Be cautious with
chmodcommands, especially with root privileges.
Last updated