Nimble Toolbox

Work out a chmod mode

For Linux, macOS, and any web host you reach over SSH. Type a mode such as 755 or 644, paste the letters from ls -l, or tick the boxes for who can read, write, and execute. The octal number, the rwx letters, and the chmod command follow each change, special bits included.

Who can do what
ReadWriteExecuteDigitOwner7Group5Others5
?
Result
Octal
755
Letters
rwxr-xr-x
Command
chmod 755 file
With letters
chmod u=rwx,g=rx,o=rx file

How to use it#

  1. Type a mode in octal or letters, paste a line from ls -l, or pick one of the common modes.
  2. Tick or untick the boxes to change who can read, write, and execute, and add setuid, setgid, or the sticky bit if you need one.
  3. Type the file or folder name to have it in the command, tick "Everything inside it too" for -R, and copy the command.

How three digits hold nine permissions#

Every file on Linux and macOS has three sets of permissions: one for its owner, one for its group, and one for everyone else. Each set has three switches, read, write, and execute, and each switch has a value: read is 4, write is 2, and execute is 1. A digit of the mode is the sum of the switches that are on, so 7 is all three, 6 is read and write, 5 is read and execute, and 4 is read alone.

The three digits run owner, group, others. So 755 is rwx for the owner and r-x for the group and everyone else, the usual mode for a program or a folder, and 644 is rw- then r-- twice, the usual mode for an ordinary file. The grid on this page shows the digit each row adds up to, so you can see where every number comes from.

The letters are the same nine switches written out, as ls -l prints them: rwxr-xr-x is 755. A line from ls -l starts with one more letter for the file type, d for a folder or - for a file, and may end in +, @, or a dot for extended permissions. Paste the whole line, name and date included, and the page reads the mode out of its first column.

What read, write, and execute mean on a folder#

On a file the three are what they sound like. On a folder they mean something else. Read lets you list the names inside it. Write lets you create, delete, and rename the things inside it, which is why deleting a file depends on the folder's permissions rather than the file's own. Execute lets you go into the folder and reach what is inside, even by a path you already know.

That is why folders almost always have execute wherever they have read. A folder at 644 can be listed but not entered, so nothing inside it can be opened, and a web server serving files from a folder with no execute for others returns an error for every one of them. Files that are not programs, on the other hand, do not need execute, which is where the common pair of 755 for folders and 644 for files comes from.

Choosing a mode#

644 suits ordinary files: you can edit them, and anyone who can reach them can read them. 755 suits programs, scripts, and folders. For anything private, such as a key or a file of passwords, use 600, or 700 for a folder. OpenSSH refuses a private key that other people can read, with "WARNING: UNPROTECTED PRIVATE KEY FILE!" and a line saying the permissions are too open, so ~/.ssh/id_ed25519 wants 600, and ~/.ssh itself is best kept at 700. Cloud keys downloaded as .pem files are often set to 400, read-only even for you.

The group digit matters when people share a project through a group: 664 for files and 775 for folders let everyone in the group edit. 777 lets every account on the machine change or replace the file, and on a web server that includes any other site or process running there. It is almost never the right fix for a permissions error. Find which account needs access and give it that, through the owner or the group.

New files get their mode from your umask, which takes permissions away from a starting point of 666 for files and 777 for folders. The common umask of 022 removes write for group and others, giving 644 files and 755 folders without anyone running chmod.

Writing the command#

chmod 755 deploy.sh sets all nine permission bits to exactly that mode. The second command on this page writes the same mode in letters, chmod u=rwx,g=rx,o=rx deploy.sh, which is easier to read in a script and also clears any setuid, setgid, or sticky bit it does not name. On a file the two do the same. On a folder they can differ, since GNU chmod leaves a folder's setuid and setgid alone when given three digits. The page quotes a name with spaces or symbols in it so the shell reads it as one name, which also means a pattern such as *.sh is taken literally.

chmod also takes changes rather than whole modes, such as chmod +x deploy.sh to add execute or chmod g-w notes.txt to take write away from the group. Those depend on the mode the file already has, so this page asks for the whole mode instead. chmod -R applies a mode to a folder and everything in it, but the same mode for files and folders is rarely what you want: run it with 755 on a folder of documents and every document becomes executable. To chmod only directories, or only files, use find: find site -type d -exec chmod 755 {} + sets the folders, and the same with -type f and 644 sets the files.

Frequently asked questions#

What does chmod 755 mean?

#

The owner can read, write, and execute, and the group and everyone else can read and execute but not change anything. In letters it is rwxr-xr-x. It is the usual mode for scripts, programs, and folders that others need to reach.

Why do I get "permission denied" running my script?

#

The script has no execute bit, which is common for a file just downloaded or written in an editor. chmod +x script.sh adds it, which with the usual umask makes a 644 file 755, and ./script.sh then runs. Running it through its interpreter, as in bash script.sh, needs only read. If the error persists with execute set, the folder it sits in may be on a drive mounted without execute, or a folder on the way may lack execute for you.

What is the difference between 644 and 755?

#

Execute. 644 is rw-r--r--, which lets the owner edit and everyone read, and 755 adds execute for all three, rwxr-xr-x. Use 644 for files that are only read, such as HTML, images, and config, and 755 for scripts and folders, since a folder without execute cannot be entered.

What are setuid, setgid, and the sticky bit?

#

They are a fourth digit in front of the usual three: 4 for setuid, 2 for setgid, and 1 for sticky. Setuid on a program makes it run as the file's owner rather than as you, which is how passwd can change a file only root can write. Setgid does the same with the group, and on a folder it makes new files inside take the folder's group rather than yours, which keeps a shared project in one group; 2775 is the usual mode. The sticky bit on a folder lets people delete only their own files in it, which is why /tmp is 1777. In ls -l they show as s or t in place of the x, and as a capital S or T when the execute under them is off, which is usually a mistake.

Why does chmod 755 not remove setgid from my folder?

#

GNU chmod, the one on most Linux systems, keeps the setuid and setgid bits on a folder when you give a mode of three digits, because clearing them by accident breaks shared folders. To clear them, give an extra leading zero, as in chmod 00755, or use letters, as in chmod g-s. Files are not treated this way.

What does a mode like -rw-r--r--@ or drwxr-xr-x+ mean?

#

The first letter is the type: d is a folder, - a file, and l a link. The nine letters after it are the permissions. A trailing + means the file also has an access control list, extra rules beyond these nine bits, which getfacl lists on Linux and ls -le on macOS. A dot marks a security label on Linux, and @ on macOS means it has extended attributes, such as the mark on a downloaded file. The page reads the mode and ignores the marks.

What does chmod 777 do, and is it safe?

#

It gives read, write, and execute to everyone, rwxrwxrwx, and it is rarely safe. Every account on the machine can then change or replace what the file holds, and on a server any compromised process can then rewrite it. When something cannot read or write a file, find which user it runs as and give that user access through the owner or the group, with 644, 664, 755, or 775.