Linux file permissions decide who can read, write or run every file on a server, and three commands, chmod, chown and umask, control them. This guide from Mintopsblog.com explains the permission model in plain terms, with examples you can test safely.
Key Takeaways
- Every file has an owner, a group and a set of read, write and execute bits for user, group and others.
- chmod changes the bits, chown changes the owner and group, and umask sets the defaults for new files.
- Numeric modes such as 644 and 755 are shorthand: read is 4, write is 2 and execute is 1.
- Give the least access that works, and avoid 777 on anything a service or web server can reach.
How the Linux Permission Model Works
Linux treats almost everything as a file, including directories, devices and sockets. Each one carries an owner (a user account), a group, and three sets of permission bits. The first set applies to the owner, the second to members of the group, and the third to everyone else, usually called “others”.
Run ls -l and you will see a string such as -rw-r--r-- at the start of each line. The first character shows the type: a dash for a regular file, d for a directory and l for a symbolic link. The next nine characters are three groups of three: read (r), write (w) and execute (x) for user, group and others.
What Read, Write and Execute Mean
The same letters mean slightly different things for files and directories, which is where many permission problems start.
| Bit | On a file | On a directory |
|---|---|---|
| r (4) | Read the contents | List the names inside it |
| w (2) | Change or truncate the contents | Create, rename or delete entries inside it |
| x (1) | Run it as a program or script | Enter it and reach files inside it (cd) |
A directory with read but no execute lets you list names but not open the files. A directory with execute but no read lets you open a file if you already know its exact name. Web servers need execute on every directory in the path to a file they serve.
Changing Permissions With chmod
The chmod manual page describes two ways to set modes: symbolic and numeric. Symbolic mode adds or removes single bits, which is safer when you only want one change. Numeric (octal) mode sets all nine bits at once.
chmod u+x deploy.shadds execute for the owner only.chmod go-w config.ymlremoves write from group and others.chmod 644 index.htmlsets owner read/write and read-only for everyone else.chmod 755 /opt/app/binlets everyone enter and run, but only the owner can change it.chmod -Rworks recursively; use it with care, because it applies the same mode to files and directories alike.
To add up a numeric mode, sum the values in each group: read 4, write 2, execute 1. So 7 is rwx, 6 is rw-, 5 is r-x and 4 is r–. A mode of 640 means the owner can read and write, the group can read, and others get nothing, which suits many configuration files that hold passwords.
Special Bits: setuid, setgid and Sticky
A fourth, leading digit holds three special bits. Setuid (4) runs a program with the file owner’s rights, setgid (2) runs it with the group’s rights or makes new files in a directory inherit its group, and the sticky bit (1) on a shared directory such as /tmp stops users from deleting each other’s files. Audit setuid files regularly, because a flaw in one can hand out root access.
Changing Ownership With chown and chgrp
Permissions only matter in relation to an owner and a group. The chown command changes both: chown www-data:www-data /var/www/site sets the user and the group in one step, and chgrp developers report.txt changes only the group. Only root can give a file away to another user, which prevents users from dodging disk quotas.
A common pattern for a shared project directory is to create a group, add the team to it, set the directory group with chown, and add setgid so new files inherit the group. That keeps collaboration working without opening files to everyone. The guide to managing services with systemd shows how service accounts fit into the same model.
Default Permissions and umask
New files do not start with random modes. Programs usually request 666 for files and 777 for directories, and the process umask removes bits from that request. With the common umask of 022, new files become 644 and new directories 755. A stricter umask of 027 gives 640 and 750, which keeps files away from “others” by default.
Run umask with no arguments to see the current value. Set it in a shell profile for interactive users, or in the unit file of a service (the UMask= setting in systemd) for daemons that create files.
Common Permission Mistakes to Avoid
- Using 777 to “fix” an error. It lets any local user or compromised process change the file. Find which user needs access and grant only that.
- Making private keys readable. SSH refuses keys that others can read; keep them at 600 and their directory at 700.
- Recursive chmod on mixed trees.
chmod -R 644strips execute from directories and breaks access. Usefindwith-type dand-type fto treat them separately. - Forgetting the parent directories. A file with the right mode is still unreachable if a directory above it lacks execute.
- Editing as root and leaving root ownership. Files created with sudo end up owned by root, so the service that needs them cannot write.
Permission work connects directly to remote access security, so read the SSH hardening checklist next, and browse more Linux administration articles or the Security and SSL section. For the full tutorial library, return to the Mintopsblog.com homepage.
Beyond the Basic Bits: ACLs
Standard permissions allow exactly one owner and one group per file. When two teams both need write access to the same directory, access control lists (ACLs) add extra entries without changing the owner. setfacl -m u:alice:rw report.csv gives one more user read and write, and getfacl report.csv shows every entry. A plus sign at the end of the mode string in ls -l tells you an ACL is present. Use ACLs sparingly and document them, because they are easy to miss when someone later troubleshoots access with ls alone. Readers who follow older Mintopsblog.com server tutorials should check the ACL support of their file system, which is enabled by default on ext4 and XFS in current distributions.
Frequently Asked Questions
What Does chmod 755 Mean?
Mode 755 gives the owner read, write and execute (7), and gives the group and others read and execute (5). It is the usual mode for directories and for scripts or programs that everyone may run but only the owner should change. Do not use it for files that hold secrets.
Is chmod 777 Ever Safe?
Almost never on a server. Mode 777 lets every user and every process on the system change or replace the file, so a single compromised account can tamper with it. If an application fails without 777, the real fix is usually the correct owner or group, not wider permissions.
What Is the Difference Between chmod and chown?
chmod changes what the owner, group and others are allowed to do with a file, while chown changes who the owner and group are. You often need both: chown to give a service account ownership, then chmod to set exactly how much access that account and everyone else receives.
How Do I Check a File’s Permissions?
Run ls -l on the file to see its type, nine permission bits, owner and group. For more detail, stat shows the numeric mode, such as 0644, along with timestamps. On a directory, ls -ld shows the directory itself instead of the files inside it, which helps when access fails.





