Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have files in /var/www that I've set permissions as follows:

user:www-data
chmod 755

How can I set it so all subsequent files uploaded (via SFTP) have those same permissions and I don't have to keep re-running chown/chgrp/chmod -R?

share|improve this question

3 Answers 3

up vote 2 down vote accepted
  • User/owner: you must login as 'user' if you want files to be created as 'user'.

  • Group: either make sure user's default group is 'www-data' or make sure all directories have the "setgid" (chmod g+s) flag set and the 'www-data' group.

  • Permissions: 'umask 022' command (meaning defaults to 0755 for dirs and 0644 for files) should be executed on login. E.g. you may put it in ~/.bashrc.

share|improve this answer

Mar_Garina has the right answer. When you create files, the value of umask is used to determine what default permissions the files are created with. I would just add that there are several places this can be set. If you want the default to be system wide for all users, it might make sense to put the umask 0222 command in /etc/profile instead of just the users personal settings. Also most ssh, sftp and ftp daemons will have an option in their server config files that specify a default umask for users that login via those systems.

share|improve this answer
    
Thanks, I've applied that to .bashrc and have also used the following command to change existing files/folders to the correct permissions: find . -type f -exec chmod 0644 {} \; Note: I couldn't use chmod -R because that would affect both directories and files equally where I wanted to target just the files inside those directories and set their permissions to 0644. –  Trent Scott May 5 '11 at 21:11

A much better answer, for 2011, is to use ACLs via setfacl:

$ setfacl -m d:user:rwx directory

Now any file created in that directory will be created with any and all default permissions you have. You can query the ACLs for any given file/directory by using the command

$ getfacl file
share|improve this answer

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.