Managing file and directory permissions is a critical aspect of using Linux. Permissions determine who can read, write, or execute a file or folder. It’s essential to understand and manage these permissions for both security and functionality purposes.
This guide provides an in-depth look at Linux folder permissions, including a comprehensive cheat sheet and FAQ section. It aims to clarify the intricacies of permissions and the commands needed to manage them.
Linux folder permissions cheat sheet
Below is a cheat sheet for Linux folder (directory) permissions commands in a table format:
||List files and directories with their permissions.|
||Set directory permissions to
||Give the owner
||Give the group
||Change the owner and group of a directory.|
||Change the owner and group of a directory recursively.|
||Change the group of a directory.|
||Change the group of a directory recursively.|
||Give a specific user
||Give a specific group
||View Access Control List (ACL) permissions for a directory.|
||Remove specific user permissions using ACLs.|
||Remove all ACLs from a directory.|
This table serves as a quick reference, but make sure to check the man pages (
man chown, etc.) for more detailed explanations and additional options.
rstands for read,
wfor write, and
chmod, the owner (
u), group (
g), and others (
o) can be adjusted. The permission modes are additive when using the
+sign and subtractive when using the
- The numeric method for
chmoduses a 3-digit octal number: the first digit represents the owner’s permissions, the second represents the group’s permissions, and the third represents the permissions for others.
- ACLs (Access Control Lists) provide more granular permissions compared to traditional Unix permissions. The
getfaclcommands help manage these.
In Linux, permissions for files and directories are often represented using symbolic (e.g.,
rwx) or numeric (often called octal) notation. The numeric representation is especially useful with the
Here’s a table that shows the numeric codes for different permissions:
|Number||Permission Type||Code Meaning|
To determine the numeric value for a combination of permissions, you’d add the numbers together. Here are some examples:
|Combination||Numeric Value||Symbolic Representation|
|Read & Write||6||
|Read & Execute||5||
|Write & Execute||3||
chmod command usage with numeric values, permissions are usually specified with three numbers, representing Owner, Group, and Others respectively. For example:
chmod 755would translate to
rwxr-xr-x: Owner has full permissions, while group and others can read and execute but not write.
chmod 640would be
rw-r-----: Owner can read and write, group can only read, and others have no permissions.
This table should help provide a clearer understanding of how numeric values correspond to permissions in Linux!
Linux folder permissions FAQ
Q1: What does
rwx stand for in permissions?
r stands for “read”,
w for “write”, and
x for “execute”. For directories,
x means the ability to access the directory.
Q2: What’s the difference between a file’s permissions and a directory’s permissions?
A: For files, the permissions are straightforward:
r allows reading the file,
w allows modifying it, and
x allows executing it (if it’s a script or a program). For directories,
r lets you list its contents,
w lets you create or delete files and subdirectories inside it, and
x lets you enter the directory and access its contents.
Q3: What does the
chmod 777 command do?
chmod 777 grants full read, write, and execute permissions to the owner, group, and everyone else for the specified file or directory. It’s usually not recommended due to security concerns.
Q4: How do I view current permissions for a file or directory?
A: Use the
ls -l command. The output will display permissions, the number of links, owner, group, size, and modification date.
Q5: What does the
chown command do?
chown command changes the owner (and optionally the group) of a file or directory.
Q6: Why can’t I enter a directory even if I have
r (read) permission?
A: To enter (or
cd into) a directory, you need
x (execute) permission on it.
Q7: What are sticky bits, and how are they useful?
A: A sticky bit on a directory ensures that only the file’s owner, the directory’s owner, or the root user can rename or delete the file. It’s often used on directories like
/tmp to prevent users from deleting or renaming others’ files. You can set it using
chmod +t <directory_name>.
Q8: How can I set default permissions for new files and directories?
A: Use the
umask command. The
umask defines the default permissions when creating new files and directories. For example, a common
umask value is
022, which means new files get
644 (rw-r–r–) and new directories get
Q9: What’s the difference between hard and symbolic (or “soft”) links in terms of permissions?
A: Hard links share the same inode and data on disk, so they always have the same permissions. Changing the permissions on one changes the permissions on all hard links to that data. Symbolic links, on the other hand, have their own permissions, but these permissions don’t matter much: what counts are the permissions of the file or directory they point to.
Q10: What are Access Control Lists (ACLs)?
A: ACLs provide a way to set more granular permissions than the traditional Unix rwx system. They allow specifying permissions for individual users and groups beyond the owner/group/other system.