DEVESSENTIALS

chmod 1777 — what does it mean?

The leading 1 is the sticky bit, more precisely the restricted deletion flag. A plain 777 directory lets any user delete any other user's files, because deletion is controlled by the directory's write bit. Adding the sticky bit closes that hole, which is why /tmp, /var/tmp and /dev/shm are 1777 on every Linux system. In ls -l the final x becomes t: drwxrwxrwt.

In plain English

1777

rwxrwxrwt

Everyone can create files in the directory, but only a file's owner, the directory's owner or root can delete or rename it.

Symbolic equivalent: chmod u=rwx,g=rwx,o=rwx,+t /srv/scratch

Open 1777 in the chmod calculator

What each digit in 1777 means

Each octal digit is the sum of read (4), write (2) and execute (1) for one class of users. The leading 1 is the special-permission digit: sticky bit (1). The other three digits are owner, group and others.

ClassDigitSumr w xls -l
Owner (u)74 + 2 + 1rwxrwx
Group (g)74 + 2 + 1rwxrwx
Others (o)74 + 2 + 1rwxrwt
  • Owner: can list the names of entries, create, rename and delete entries and enter the directory and open files by name.
  • Group: can list the names of entries, create, rename and delete entries and enter the directory and open files by name.
  • Others: can list the names of entries, create, rename and delete entries and enter the directory and open files by name.
  • sticky bit: the others' x shows as t; only a file's owner, the directory's owner or root can delete or rename entries.

When to use chmod 1777

  • /tmp, /var/tmp and /dev/shm. If one of these is 777 or 755 after a restore or a container build, set it back with chmod 1777.
  • Shared scratch or drop-box directories where many users create files but must not remove each other's, e.g. a shared upload area on a lab server.
  • Directories in container images that any runtime UID must be able to write to, such as a temp directory used by an app running as an arbitrary user.

Security risks and gotchas

It does not protect file contents

The sticky bit only restricts deleting and renaming. Each file's own mode still decides who can read or modify it. Create files in /tmp with umask 077 or mktemp (which creates 600 files) if they hold anything sensitive.

tmpfile=$(mktemp)   # created as -rw-------

Predictable names are an attack surface

In a shared world-writable directory, another user can create /tmp/myapp.lock or a symlink with that name before your program does. Always use mktemp or mkdtemp rather than fixed names. Linux mitigates some of this with the fs.protected_symlinks and fs.protected_regular sysctls.

Capital T means others lack execute

If you set the sticky bit on a directory others cannot enter (e.g. 1770), ls -l shows rwxrwx--T. That is valid. On regular files, Linux ignores the sticky bit entirely.

Commands

Make a shared scratch directory

sudo mkdir -p /srv/scratch
sudo chmod 1777 /srv/scratch

Equivalent to chmod a=rwx,+t /srv/scratch, or chmod +t on an existing 777 directory.

Repair /tmp

sudo chmod 1777 /tmp

Many programs (and some package scripts) misbehave or refuse to run when /tmp lacks the sticky bit.

Find world-writable directories without the sticky bit

find / -xdev -type d -perm -0002 ! -perm -1000 2>/dev/null

These let any user delete other users' files and should usually be 1777 or not world-writable at all.

How to check for 1777

# Symbolic view
ls -ld /srv/scratch
drwxrwxrwt  18 root root  4096 Oct 16 09:12 /srv/scratch

# Octal view (Linux / GNU coreutils)
stat -c '%a %A %n' /srv/scratch
1777 drwxrwxrwt /srv/scratch

# Octal view (macOS / BSD)
stat -f '%Mp%Lp %Sp %N' /srv/scratch

The first character of the ls -l output is the file type (- regular file, d directory), followed by the nine permission characters. stat -c %a prints the octal mode directly; it only shows a fourth leading digit when setuid, setgid or the sticky bit is set.

Related chmod modes

Try variations of 1777 in the chmod calculator, browse all chmod modes, or read Linux file permissions explained for chown, umask and ACLs.

Frequently Asked Questions

Why is /tmp 1777 and not 777?▾

Every user needs to create files in /tmp, so it must be world-writable. Without the sticky bit, any user could also delete or replace other users' temp files. The sticky bit limits deletion and renaming to the file's owner, the directory's owner and root.

What does the t in drwxrwxrwt mean?▾

Lowercase t in the others-execute position means the sticky bit is set and others also have execute. Uppercase T means the sticky bit is set but others do not have execute.

Does the sticky bit do anything on files?▾

Not on Linux, which ignores it for regular files. Historically it told the kernel to keep a program's text in swap, which is where the name comes from.