A single chmod 777 or a forgotten setuid binary can give an account far more access than it needs. On a shared Linux server, that one setting can be enough for a cyber criminal to move from a low-privilege account to root.
File permissions are where least privilege starts on Linux. Every user, group and process should only have the access it requires for its job. Below are the commands that control those permissions, the mistakes that undo them and how to manage access as your server count grows.
Linux file permissions define which users and groups can read, write or execute a file or directory. Each file has permissions assigned to the owner, group and others, using combinations of read (r), write (w) and execute (x) rights to control access and enforce system security.
In Linux, a user is more than just a name; it's a distinct identity defined by a user ID (UID). Permissions on files and processes are checked against that identity and its groups. To streamline access control, users can be grouped under a group ID (GID), which allows administrators to manage permissions for multiple users at once, an approach called group-based access control.
Each user is assigned to a primary group, typically created automatically with the same name as the user account (a user private group). This group sets the default group ownership of files and processes the user creates. Beyond that, users can be added to one or more secondary groups, enabling access to additional shared files and directories across the system.
Most major distributions, including Debian, Ubuntu and RHEL, default to the user private group model, though administrators can configure this differently.
User and group information lives in plain text files:
/etc/passwd. Stores basic user account details./etc/group. Tracks group memberships.To inspect user details and group memberships, use these commands:
id username. Shows the UID, GID and all associated groups.groups username. Lists only the group names the user belongs to.Group membership is where least privilege starts. Every secondary group adds access, so review memberships regularly and remove the ones a user no longer needs.
Linux permissions fall into three types: read (r), write (w) and execute (x). They mean slightly different things for files and directories.
| Permission | On a file | On a directory |
| Read (r) | View the contents | List the contents |
| Write (w) | Change the contents | Create, delete and rename entries inside (also requires execute) |
| Execute (x) | Run the file as a program | Enter and navigate the directory |
Deleting a file depends on write permissions in the directory that contains it, not on the file itself.
The rwx permission triplet represents the permissions for each category: owner, group and others. This representation using letters is called symbolic mode.
Take this permission string, for example:
-rwxr-xr--
The permission triplet can also use octal notation, which represents permissions as r = 4, w = 2, x = 1, and - = 0. The values of each triplet are added together to form a single digit.
In octal, -rwxr-xr-- becomes:
Together, that's 754.
As an admin, you can change Linux permissions for files and directories through the chmod command-line utility. chmod stands for “change mode,” and you can use it in both symbolic and octal modes.
In symbolic mode, use chmod with the symbols +, - and = to add, remove or set specific permissions, followed by the file name. The letters u, g and o stand for the owner, group and others.
For instance:
chmod u+x filename.txt
This adds execute permissions for the owner only, without affecting the group or others.
In numeric mode, chmod is followed by the octal permissions and the file name:
chmod 754 filename.txt
This translates to -rwxr-xr--, which means the file owner can read, write and execute, the group can read and execute, and others can only read the file.
To update the permissions of a directory and everything inside it, use the recursive (-R) option with chmod:
chmod -R 754 my_dir
This sets my_dir and every file and directory inside it to 754 (read, write and execute for the owner; read and execute for the group; read for others).
A numeric recursive mode applies the same permissions to files and directories, which can make every file in the tree executable. To avoid that, use the symbolic X, which adds execute only to directories and files that are already executable:
chmod -R u=rwX,g=rX,o=r my_dir
NOTE: Use recursive chmod cautiously. One mistake can change permissions across thousands of files and grant far more access than intended.
When you create a new file or directory on Linux, its default permissions automatically apply. Before umask is applied, the default for files is 666 (rw-rw-rw-) and for directories it's 777 (rwxrwxrwx).
You can control these default permissions by setting the umask, which clears permission bits from the defaults. The umask is a bitmask, usually written as three or four octal digits (for example, 022 or 0025), where each digit marks the permissions to deny for the owner, group and others. The result is the default with the umask bits cleared.
Permissions = Default AND NOT umask
For instance, an umask of 022 gives new files 644 (rw-r--r--) and new directories 755 (rwxr-xr-x). A umask of 027 gives new files 640 (rw-r-----) and new directories 750 (rwxr-x---), so other users can't read anything new by default.
Special permission bits change how programs and directories behave. Setuid and setgid allow a program to run with the privileges of its owner or group, which is why they require careful auditing. The bits are:
/tmp so users don’t accidentally delete files they don’t own.Access control lists (ACLs) give you finer control over permissions than the traditional owner, group and others model. They let you define specific access rights for individual users or groups without changing base file ownership. That makes them useful for least privilege: you can give one user access to one file without exposing the whole group.
On current distributions, ACL support is enabled by default on common file systems such as ext4 and XFS. On older systems, you may need to enable it with the acl mount option.
ACLs have two main commands: getfacl and setfacl. getfacl lets you view the ACLs on a file or directory and setfacl lets you modify or add ACL entries.
For instance, to view the ACLs for a file named fidel.txt, use:
getfacl fidel.txt
To give a user read and write access, use this basic syntax:
setfacl -m u:alice:rw testfile.txt
Changing file ownership and group in Linux is another way to control permissions and access. To do this, you can use either the chown or chgrp command. Keep in mind that changing ownership requires you to have sudo or root privileges.
For instance:
sudo chown esther filename.txt
This changes the ownership of the file filename.txt to the user esther.
To change the group ownership of filename.txt to the expats group, use chgrp:
sudo chgrp expats filename.txt
You can also change both the owner and the group with one command:
sudo chown esther:expats filename.txt
Mistakes happen, especially when permissions are managed by hand. These are the most common ones and how to avoid them:
chmod 777, can expose your Linux system to cyber criminals if they are not monitored. Avoid them, except in rare cases, like in the /tmp directory, which is world-writable but protected by the sticky bit. You can also use umask to restrict default Linux permissions. ls -l command, and use ACLs for granular control, especially for collaborative environments. find / -perm -4000 -type f 2>/dev/null
Linux file permissions will always matter, but they shouldn't be your only line of defense. They control what an account can do once it's on a server. Privilege Control for Servers adds controls around who gets privileged access to your Linux servers, how much they get and for how long:
File permissions still decide what each account can do on the host, so keep managing them carefully. With least privilege enforced around them, a single permission mistake is less likely to lead to a breach.
See how it works: try an interactive demo of Privilege Control for Servers.