chmod 2755 rwxr-sr-x

chmod 2755 (rwxr-sr-x): the owner can read, write and execute; group and others can read and execute, with setgid. Commands, umask and security notes.

Octal
2755
Symbolic
rwxr-sr-x
ls -l shows
-rwxr-sr-x for a file, drwxr-sr-x for a directory
chmod letters
u=rwx,g=rxs,o=rx

Who can do what

ClassDigitBitsOn a fileOn a directory
Owner (u)7rwxRead the contents, change or empty the contents and run it as a programList the names inside, create, delete and rename entries and enter it and open files by name
Group (g)5r-xRead the contents and run it as a programList the names inside and enter it and open files by name
Others (o)5r-xRead the contents and run it as a programList the names inside and enter it and open files by name

Each digit adds read (4), write (2) and execute (1). Deleting or renaming a file depends on write and execute on the directory that holds it, not on the file's own mode. Root bypasses read and write checks.

Special bits

Setgid (2)
On a program: it runs with the file's group. On a directory: new files and subdirectories take the directory's group, and new subdirectories inherit setgid. Shown as s in the group's execute place.

Typical uses

Setgid plus 755. On a program, it runs with the file's group whoever starts it. On a directory, new files and subdirectories take the directory's group instead of the creator's, and new subdirectories inherit the setgid bit.

Security notes

  • Setgid on a program lets anyone run it with the file's group; on a directory it only changes group ownership of new files, which is harmless.
  • Only the owner (and root) can change it; the group and others are limited to the read and execute rights shown above, which is the usual safe pattern for shared files and directories.
  • Every account on the machine can read it, so keep passwords, keys and tokens out of anything with this mode.

Commands

  • Numeric
    chmod 2755 file
  • Symbolic
    chmod u=rwx,g=rxs,o=rx file
  • Check the result
    stat -c '%a %A %n' file
  • Directories only, recursively
    find /path -type d -exec chmod 2755 {} +

Avoid chmod -R 2755 on a tree that holds files as well as folders: it makes every file executable. Use the find command above for directories and a file mode such as 644 for the files.

The umask that gives 2755

No umask produces 2755: a umask only removes bits from 666 for files and 777 for directories, and it never sets setuid, setgid or the sticky bit. Set it with chmod after creating the file or directory.

Other common modes

Work out any other mode in the chmod calculator