Problem

You want to create a directory on your Mac under /var/backups, .e.g. /var/backups/blog and make it writable for your user. So you open a terminal and execute

sudo mkdir /var/backups/blog \
&& sudo chown $(id -u):$(id -g) /var/backups/blog \
&& sudo chmod 700 /var/backups/blog

This leads to a new folder under /var/backups that belongs to your user and group and which has read, write, and execute access-rights only assigned to your user (chmod 700):

apoehlmann:~$ ls -lah /var/backups/ | grep blog
drwx------   3 apoehlmann  staff    96B Jan 18 16:55 blog

However, you still cannot create any file in that directory:

apoehlmann:~$ touch /var/backups/blog/test.txt
touch: /var/backups/blog/test.txt: Permission denied

Solution

Citing StackExchange: "This happens because there is a directory higher in the tree where you do not have execute permission."

Turns out, on macOS /var/backups has different default access rights than on Ubuntu:

apoehlmann:~$ sudo ls -lah /private/var | grep backups
drwx------   3 root          wheel           96B Jan 18 16:29 backups

Which effectively translates to 700 access rights. However, we need 755. So chmoding it fixes the problem:

apoehlmann:~$ sudo chmod 755 /private/var/backups
apoehlmann:~$ touch /var/backups/blog/test.txt
apoehlmann:~$ ll /var/backups/blog/
total 0
drwx------  3 apoehlmann  staff  96 Jan 18 16:55 ./
drwxr-xr-x  3 root        wheel  96 Jan 18 16:29 ../
-rw-r--r--  1 apoehlmann  staff   0 Jan 18 16:55 test.txt

Bonus info

By default, /var/backups on Ubuntu 18.04 has the desired access rights:

apoehlmann:~$ docker run --rm -it ubuntu bash
root@c16df1955a52:/# ls -lah /var | grep backups
drwxr-xr-x 2 root root  4.0K Apr 24  2018 backups
root@c16df1955a52:/#
Getagged mit:
macOS
blog comments powered by Disqus