I have a centos server that one of my apps creates files in a tmp folder. The files are always created with the permissions r--r--r-- and i need all the new files in this directory to be created with at the least, the permissions rw-rw-rw-.

How can i achieve this?

EDIT Here's my current setup. I've chmod 777 everything in the /page folder. Then when i run something in my app, it creates or modifies files and they are not rw-r--r--.


ls -ald
drwxrwsrwx 2 tomstest psacln 12288 Aug  2 20:32 .


ls -al
-rw-r--r--  1 tomstest psacln     2 Aug  2 20:32 size
-rwxrwxrwx  1 tomstest psacln     5 Jul 20 16:58 version

My app errors I think because of the line that is rw-r--r--.

  • 1
    NEVER chmod 777. Is tomstest the user that your app is running as? – quanta Aug 3 '12 at 3:38
  • Yes I think it is. – Catfish Aug 3 '12 at 4:14
  • Is there a good way to check what user the app is running under? It's a rails app if that's relevant. – Catfish Aug 3 '12 at 4:16
  • Actually it might be running as root. The reason it's set to user tomstest is because i chown'd/chgrp'd/chmod'd the entire folder. – Catfish Aug 3 '12 at 4:17

umask can help but DON'T do this. Why did you want to give other user the write (w) permission?

  • Because the app needs to add and delete files and it bombs when deleting those tmp files. – Catfish Aug 3 '12 at 2:51
  • What do you mean "bombs"? Why not 664? – quanta Aug 3 '12 at 2:53
  • My app throws an error because it can't delete the file. 664 would probably work too. – Catfish Aug 3 '12 at 3:13
  • What error? Which user your app is running as? Who is owner of those tmp files? – quanta Aug 3 '12 at 3:15
  • It's an error in my rails app. Permission denied is the error. – Catfish Aug 3 '12 at 3:33

I think everyone else is doing a great job of providing answers, but there's one wrinkle that hasn't been addressed. You specifically mention that your app has a problem when deleting files, but then focus entirely on the protection mode of the files themselves. You should be aware that the ability to delete a file under Unix isn't dependent on the owner or protection mode of the file itself, but of the ownership and protection mode of the directory the file is in. Don't overlook that when seeking the answer to this question!

  • Interesting...I was not aware of this. I'll have to check the owner of the directory. – Catfish Aug 3 '12 at 13:14
umask 0

Append the command to your ~/.bashrc file to make it permanent.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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