Score:0

Why don't I have permission to create this directory / file? Permissions on Debian 11 Linux

ca flag

I thought I understood Linux permissions, but alas... why don't I have permissions here?

I'm part of the www-data group:

docker@docker01:/home/docker$ id
uid=1002(docker) gid=998(docker) groups=998(docker),33(www-data)

The parent directory is user/group www-data, and the group has rwx:

docker@docker01:/home/docker$ ls -lh /var/www/userdata02.example.com/html/
total 40K
drwxrwxr-x 768 www-data www-data 20K Jun  1 08:01 private
drwxrwxr-x 777 www-data www-data 20K Jun  5 20:55 public

But when I try to create a new subdirectory, I get a permissions error:

docker@docker01:/home/docker$ mkdir /var/www/userdata02.example.com/html/public/803y9xcn

mkdir: cannot create directory ‘/var/www/userdata02.example.com/html/public/803y9xcn’: Permission denied

What am I missing here...?

Ginnungagap avatar
gu flag
Does it work when creating the folder as root?
Keith Palmer Jr. avatar
ca flag
Yes, I can create folders in that directory as `root`.
Score:0
za flag

Permissions are rwxrwxr-x which mean rwx for owner ("read-write-execute"), rwx for group, r-x for others.

For directories, "read" flag (r) means "get a directory listing", "write" (w) means "create/delete/rename objects" in that directory, and "execute" (x) is "enter" (cd) into that directory.

Changes (w) are permitted only for owner or owner-group. You're docker and you aren't the owner which is www-data. Likely docker doesn't belong to the www-data group, so you are one of those "others", who are not permitted to write.

This could be solved:

  • by using POSIX ACL to add permissions specifically for the docker user or group it belongs to;
  • by adding docker into www-data group;
  • by changing permissions to be world-writable.

Options are presented in the order of decreasing security (as opposed to increased ease of implementation). In addition, two lower options have a caveat: newly created objects will be owned by docker and now www-data won't have control over them; it could be it will not able to delete them or even read, that depends on what permissions objects are created with. It's messy and I suggest to not do that. I'd explain the POSIX ACL path:

setfacl -m user:docker:rwx /var/www/userdata02.example.com/html/public
setfacl -m default:user:docker:rwx /var/www/userdata02.example.com/html/public
setfacl -m default:user:www-data:rwx /var/www/userdata02.example.com/html/public
setfacl -m default:group:www-data:rwx /var/www/userdata02.example.com/html/public

Even in first case objects will be owned by creator (docker), but you can have a "default" ACL which will be applied to all new objects and nested to subdirectories, so you can force all new object to have full permissions for www-data. This is what three lower lines are for.

Or, you can create a special group for such object and instead of giving permissions to user:docker give them to group:that_group. Depending on what you are going to do in Docker, it might make your life easier later.

Keith Palmer Jr. avatar
ca flag
If you look at my question, the `docker` user _is_ part of the `www-data` group already.
Nikita Kipriyanov avatar
za flag
Yes, I missed that somehow. Sorry. Are you sure there is no object in that directory with the name you are going to create? Also, any chances you hit an AppArmor denial? Show `cat /sys/module/apparmor/parameters/enabled`; look for `DENIED` in `/var/log/syslog`.
Keith Palmer Jr. avatar
ca flag
So this returns `Y`: `/sys/module/apparmor/parameters/enabled` I don't see anything in `syslog` though.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.