Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question

3 Answers 3

up vote 5 down vote accepted

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.

share|improve this answer
2  
it is good practice to mount it with the "noexec" option, expecially if its on a server/multiuser enviroment –  Mr Shunz Jun 17 '10 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 '11 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. –  Mr Shunz Mar 29 '11 at 7:36

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.

share|improve this answer
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 '10 at 2:15

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.

share|improve this answer
    
Also "/tmp" is a good candidate for tmpfs (being fully in virtual memory) –  Vi. Jun 17 '10 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 '11 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 '11 at 15:08

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.