4

I'm wondering if /tmp should be owned by root, or rather nobody? Now with safe mode there are some conflicts, but I am worried about security if I change it to be owned by nobody...

Any advice will be very appreciated.

3 Answers 3

7

It should be owned by root, but must be readable and writable by anyone with one important factor: the sticky bit on the directory must be set in order to make it an append-only directory. In other words, only users who own a file inside the /tmp directory and have read/write permissions can remove or rename the file. You may read the man page for sticky(8) for more information on what the sticky bit is.

3
  • 2
    it is good practice to mount it with the "noexec" option, expecially if its on a server/multiuser enviroment Jun 17, 2010 at 15:53
  • @MrShunz: Is there some benefit to using "noexec"? It would certainly be inconvenient for users using /tmp as a "scratch area" for e.g. writing throwaway scripts.
    – sleske
    Mar 29, 2011 at 2:39
  • 1
    @sleske actually, if it's your personal machine not much, but if it is a server in which, for example, php scripts can write to /tmp it's usually safer to mount it noexec so no malicious scripts can be injected and executed. Mar 29, 2011 at 7:36
3

Can a file be owned by nobody? What OS are you using?

Under Linux, /tmp is owned by root, is world-writable and has the sticky bit set. It means that anyone can create files but only the owner (or root) can remove them. It should be similar on most Unix systems, though.

1
  • 1
    "nobody" is the name of an account on a typical Unix system. Apparently, it used to be used to run many daemons; these days it's recommended to give most daemons their own accounts so that they won't interfere with each other (so that if, say, a security problem in one of them allows an attacker to gain control over it, the attacker will not immediately be able to gain control over any other daemons), and it looks like the main point of "nobody" is for NFS to map "root" from other systems to...
    – SamB
    Jun 18, 2010 at 2:15
2

Yes, it should be owned by root, but it should also be world writable with sticky bit, so that other programs can use it as a temp directory and files created there are owned by the creator. I'm not sure of the standard practice these days, but I would also recommend making /tmp its own partition, and not part of the root partition, so that if it gets filled up it doesn't hose the root partition.

3
  • Also "/tmp" is a good candidate for tmpfs (being fully in virtual memory)
    – Vi.
    Jun 17, 2010 at 18:37
  • @Vi: Interesting idea. However, wouldn't that create problems if programs create large files in /tmp (e.g. temporary files during video editing / encoding)?
    – sleske
    Mar 29, 2011 at 2:42
  • @sleske, Yes, it would, so I override TMPDIR from time to time. Also my /tmp is "noexec" which also creates problems.
    – Vi.
    Mar 29, 2011 at 15:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .