You can use Access Control Lists (ACLs) for this, giving additional permissions to a specific user for a particular file or directory.
First off, make sure that the filesystem in question has the acl
option enabled: commonly it will by default, but you can add it to the options in fstab
(and/or remount).
With ACLs enabled you control the ACL on a particular file or directory using the setfacl
command:
setfacl -m "user:vonflynee:rwx" /home/foo/www
That sets a per-user permission for user vonflynee
of rwx
(formatted as in chmod
) for that particular directory, in addition to the permissions the owner of the file already has. You can have multiple ACL specifications for a particular file for different users and groups that you need to deal with, and they can have any combination of different permissions.
As with other permissions, you need to be able to traverse the whole tree up to the file you want to access, so you may need to set others further up the tree, and you'll need access to the files too. setfacl
supports a --recursive
mode to set permissions on a whole tree.
The Arch wiki has a moderately comprehensive article on the subject with Arch-specific parts of the process highlighted.
Another option, and the more conventional one, is simply to make a new group "vonflyneeandfoo
", add both users to it, chown -R
the directory to that group, chmod g+s
the directory so that new files inherit its group, and then chmod -R g+rX dir
to give the files group write permission.
If there's only this single case you need to deal with this is likely to be the simpler option. Even if it is, if you have many local users and you're relying on apache
being a group member already then making the read permissions work out is harder and ACLs will be more convenient for you.