Skip to content
Log In Sign Up info@muvcloud.com

Read the Permission String

ls -l deploy.sh
-rwxr-x--- 1 deploy www-data 812 Nov 30 10:15 deploy.sh

The first character is the type: - for a file, d for a directory, l for a symbolic link. Then come three groups of three: the owner (rwx), the group (r-x), and everyone else (---). A dash means the permission is not set.

LetterOn a fileOn a directory
rRead itList names
wChange itAdd, delete, rename
xRun itEnter it

Numeric Modes

Each permission has a value: read 4, write 2, execute 1. Add them per set, and write the three sums in the order owner, group, others:

DigitMeans
7rwx
6rw-
5r-x
4r--
0---
chmod 640 config.ini

This gives the owner read and write, the group read, and others nothing.

Common Values

ModeTypical use
644Normal files, web pages
755Directories, scripts
600Private keys, secrets
700Private directories
640Config read by a group

Symbolic Modes

Letters name who is affected (u owner, g group, o others, a all), an operator (+ adds, - removes, = sets exactly), and the permissions:

chmod u+x deploy.sh         # owner may run it
chmod g-w report.txt        # group loses write
chmod o= secret.txt         # others get nothing
chmod a+r index.html        # everyone may read
chmod u=rw,go=r notes.txt   # same as 644

A symbolic mode changes only the bits it names; a numeric mode sets all of them at once. The most common case, chmod +x, is covered in how to make a file executable in Linux.

Directories, -R, and Capital X

A warning first: -R changes a directory and everything below it, and there is no undo. Never run it on / or on system directories such as /etc, /usr, or /var, where wrong modes can break sudo, SSH, and services. Check the path with ls -ld, and use the narrowest directory that does the job.

A capital X sets execute only on directories, and on files that already have execute for someone, which makes it the safe way to fix a web root in one command:

ls -ld /var/www/example.com
chmod -R u=rwX,go=rX /var/www/example.com

Directories end up as 755 and files as 644; a file that already had an execute bit, such as a script, ends up as 755. Other methods, with find, are in chmod recursive.

Special Bits

A fourth, leading digit sets setuid (4), setgid (2), and the sticky bit (1): chmod 2775 shared/ makes new files inherit the directory's group, and the 1777 mode of /tmp lets users delete only their own files. See sticky bit for the details.

Copy Permissions from Another File

chmod --reference=good.conf new.conf

The second file gets the same mode as the first. To see a mode as a number before you copy it, run stat -c '%a' good.conf.

Why Not 777

Mode 777 lets every user and every process on the server change or replace the file, including a compromised web application. When something "only works with 777", the real fix is almost always ownership: give the file to the right user with the chown command. The risks are explained in chmod 777.

Where Default Permissions Come From

New files start from 666 and new directories from 777, minus the bits in your umask. With a umask of 022, files are created as 644 and directories as 755. How to read and change it is in umask.

Updated:

Linux VPS with Full Root Access

MUVCloud cloud servers run on KVM with Enterprise NVMe SSD storage and full root access, in Turkey, the Netherlands, and the USA.

Cloud VPS Plans Starting at2.99 $/mo Cheap Linux VPS

No Limits on Service or Support

You are not on your own as your projects grow. Our support engineers are ready 24/7, on several channels, whenever you need them.

Support specialist
  • 100% customer satisfaction goal
  • Our own hardware
  • 24/7 ticket and email support
  • 4 countries with locations