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
?
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.
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.
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