0

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?

3 Answers 3

2
  • 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.

1

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.

1
  • 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. May 5, 2011 at 21:11
0

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

You must log in to answer this question.

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