The normal settings for /tmp
are 1777 aka a=rwx,o+t
, which ls
shows as drwxrwxrwt
. That is: wide open, except that only the owner of a file (or of /tmp
, but in that case that's root
which has every right anyway) can remove or rename it (that's what this extra t
bit means for a directory).
The problem with a /tmp
with mode 777 is that another user could remove a file that you've created and substitute the content of their choice.
If your /tmp
is a tmpfs filesystem, a reboot will restore everything. Otherwise, run chmod 1777 /tmp
.
Additionally, a lot of files in /tmp
need to be private. However, at least one directory critically needs to be world-readable: /tmp/.X11-unix
, and possibly some other similar directories (/tmp/.XIM-unix
, etc.). The following command should mostly set things right:
chmod 1777 /tmp
find /tmp \
-mindepth 1 \
-name '.*-unix' -exec chmod 1777 {} + -prune -o \
-exec chmod go-rwx {} +
I.e. make all files and directories private (remove all permissions for group and other), but make the X11 sockets accessible to all. Access control on these sockets is enforced by the server, not by the file permissions. There may be other sockets that need to be publicly available. Run find /tmp -type s -user 0
to discover root-owned sockets which you may need to make world-accessible. There may be sockets owned by other system users as well (e.g. to communicate with a system bus); explore with find /tmp -type s ! -user $UID
(where $UID
is your user ID).
chown
orchmod
?chmod
. chown (like ch - own), is about ownership of files, which user owns a file. chmod (like ch - modifify) is more about who can execute, or write inside, or read the content of a file.chown 777
which sets the ownership of a file to the user with the ID 777. However, all the answers, including the accepted one, work withchmod
. Since all of them set the permission to the same value for all the users (owner, group, others), most effects of the file ownership become irrelevant. However, the correct command to rectify the result ofsudo chown 777 -R /tmp
should besudo chown root -R /tmp
.