chmod 1777 or 3777 on /tmp

Is there an ideal chmod for /tmp (with /var/tmp symlinked to /tmp)?

I've seen people mention it both ways just curious as to the difference.

Is it a security difference?


Solution 1:

Setting it to 1 sets the sticky bit. Setting it to octal 3 is actually setting octal 2, which is setting the setgid bit, and setting octal 1, the sticky bit.

When the setgid bit is set on a directory all files (or directories) created in that directory will belong to the group that owns the directory. When the sticky bit is set only the owner and root can delete it.

The norm for /tmp is 1777.