1

I've set the owner of my sites files to be: www-data with a 755 permission. Now, I need to run some commands as me.

I get permission errors.

How can I allow my user to run cmds on these files but yet still have www-data as the owner? i do not wish to set 777 permissions.

panthro
  • 286
  • 1
  • 4
  • 12
  • You should use POSIX ACLs and leave the permissions as is on the folder, IMHO. –  Oct 21 '16 at 16:30

2 Answers2

2

Linux does not allow two users to be the owner. This is what groups are for. Create a new group (ex. wwwgroup and put both www-data and you in that group. Then, set the group for the site's files to be wwwgroup.

Here's how to do it:

sudo groupadd wwwgroup
usermod -aG wwwgroup www-data
usermod -aG wwwgroup <YOUR-USER-NAME>
1

POSIX Access Control Lists (ACLs) are more fine-grained access rights for files and directories. An ACL consists of entries specifying access permissions on an associated object. ACLs can be configured per user, per group or via the effective rights mask.

More information can be found here.

It should be noted, that in 14.04 and newer, POSIX ACLs will work out of the box and need no additional packages installed.


The following command will set the ACL recursive, for the user 'yourusername' to have read, write, and execute permissions on /var/www-data and beyond.

setfacl -R -m u:yourusername:rwx /var/www-data

To see the ACL's set for the folder...

getfacl /var/www-data

And to remove the ACL you just set...

setfacl -x u:yourusername /var/www-data