How to use the Chmod Calculator
- Tick the read, write and execute boxes for the owner, the group and others. Or start from a preset such as 644 or 755.
- Read the octal number and the symbolic string. Edit either field and the checkboxes follow.
- Copy the finished command. Change the file name first if you want it in the command.
- To change an existing mode the way chmod does, type something like u+x or go-w into the last box. The result shows before you load it.
How the octal number is built
Each class of user gets one digit made by adding read = 4, write = 2 and execute = 1. Read and write is 4 + 2 = 6, read and execute is 4 + 1 = 5, and all three is 7. The digits come in the order owner, group, others, so 755 means rwx for the owner and r-x for group and others, and 644 means rw- for the owner and r-- for everyone else.
A fourth leading digit holds three special bits: setuid = 4, setgid = 2 and the sticky bit = 1. So 4755 is 755 with setuid, and 1777 is the usual mode of a shared temporary directory. In the ls -l form these bits replace the x in the owner, group or others position: a lowercase s or t means the bit is set and execute is also set, and a capital S or T means the bit is set without execute.
What the permissions mean
For a file, read lets you see the contents, write lets you change them and execute lets you run it as a program. For a directory, read lists the names inside, write lets you create, rename and delete entries, and execute (also called search) lets you open the directory and reach what is inside it. A directory without execute for you is closed even if you can read it.
Setuid and setgid make a program run with the permissions of its owner or group instead of the person who started it, so use them sparingly. On a directory, setgid makes new files inherit the directory's group, and the sticky bit stops users from deleting or renaming files they do not own.
Choosing a mode
Use 644 for ordinary files and 755 for programs and directories. Use 600 and 700 for private files such as SSH keys, which the ssh client refuses to use if other users can read them. Avoid 777: it lets every user on the machine modify the file, which is almost never needed.
Frequently asked questions
What does chmod 755 mean?
The owner can read, write and execute (7 = 4 + 2 + 1). The group and everyone else can read and execute (5 = 4 + 1) but not write. In letters it is rwxr-xr-x.
What is the difference between chmod 644 and 755?
644 (rw-r--r--) has no execute bit for anyone, so it suits documents, images and configuration files. 755 (rwxr-xr-x) adds execute, so it suits scripts, programs and directories.
Why is 777 considered unsafe?
It gives read, write and execute to every user and process on the system. A bug or a compromised account can then change the file. Pick the narrowest mode that works, usually 644, 755 or 664.
Does chmod 755 clear setuid or setgid on a directory?
No. For directories, GNU chmod keeps the setuid and setgid bits unless you set them explicitly. To clear them with a number you need a fifth leading zero such as 00755, or use a symbolic mode such as g-s.
What does the capital S or T mean?
The special bit is set but the matching execute bit is not. A setuid bit on a file that is not executable by its owner has no useful effect, so rwS usually points to a mistake.
Sources
Last reviewed