chmod command in Linux: file permissions (755, 644, rwx)
Updated November 1, 2026
The chmod command changes a file's permissions: who can read, write, and execute it.
Syntax
chmod mode fileYou set the mode two ways: symbolic (u+x) or an octal number (755).
Common cases
chmod +x script.sh # make a file executable
chmod 644 file.txt # rw-r--r--: owner writes, others read
chmod 755 script.sh # rwxr-xr-x: owner all, others read and run
chmod -R 755 public/ # recursively for a directory and everything in itSample output
$ ls -l hello.sh
-rw-r--r-- 1 student student 20 Jul 26 03:50 hello.sh
$ ./hello.sh
bash: ./hello.sh: Permission denied
$ chmod +x hello.sh
$ ls -l hello.sh
-rwxr-xr-x 1 student student 20 Jul 26 03:50 hello.sh
$ ./hello.sh
hiHow it works: where the numbers come from
A file has three permission groups: owner, group, others. Each has three bits: read
r= 4, writew= 2, executex= 1. A digit in the mode is their sum: 7 = rwx, 6 = rw-, 5 = r-x, 4 = r--. So755means rwxr-xr-x and644means rw-r--r--. Files are usually 644, directories and scripts 755. The777mode opens write access to everyone and is almost always a security hole.
Try it
Open the sandbox: a real throwaway Linux terminal in your browser. Run the commands above by hand. The container is deleted when you leave, so there is nothing to be afraid of breaking.
Where this is in the book: the chapter Users, groups, permissions.
Common mistakes
On a directory the x bit means "enter", not "run". Take it away and the directory closes to you as well. After chmod -R 644 tree, chmod itself stops halfway with chmod: cannot access 'tree/notes.txt': Permission denied, ls tree still shows the name notes.txt, while ls -l tree answers ls: cannot access 'tree/notes.txt': Permission denied and prints question marks where the permissions belong. cd tree says bash: cd: tree: Permission denied. You are still the owner of the directory, so chmod -R 755 tree puts it back.
chmod -R 755 public/ puts the execute bit on every file inside, notes.txt and images included: ls -l shows them as -rwxr-xr-x. Data files have no use for that bit, and it misleads whoever reads the listing next. Recursion has a capital X for this: chmod -R a+X tree sets x on directories and on files that already had it, and leaves notes.txt at -rw-r--r--.
A script needs r on top of x. Run a file with mode 111 (---x--x--x) and the answer looks odd: /bin/bash: ./s.sh: Permission denied, even though the execute bit is right there. The kernel reads the first line of the file, sees #!/bin/bash, starts /bin/bash and hands it the path, and bash cannot open the file for reading. A compiled program runs with x alone; a script needs r-x.