I am running Debian Jessie with pixel. I have a file located at /home/pi/robotAI/static/sqlite/robotAI.sqlite which I need NGINX to access. NGINX runs as www-data and normally when I run the following everything is fine
sudo chown -R pi:www-data /home/pi/robotAI/static/sqlite
sudo chmod -R 777 /home/pi/robotAI/static/sqlite
However for some reason after rebuilding my Pi this approach does not work any more. The problem appears to be that despite granting all permissions as above, the www-data user still cannot access the file. To test this I run the following as the Pi user
ls /home/pi/robotAI/static/sqlite
and I get a display of the content of the folder. However if I run the following command to test as www-data then I get permission denied.
sudo -u www-data ls /home/pi/robotAI/static/sqlite
If I check the permissions on the folder contents using the command below then I get the results shown.
ls -la /home/pi/robotAI/static/sqlite
total 136
drwxrwx--x 2 pi pi 4096 May 6 14:55 .
drwxrwxrwx 3 pi www-data 4096 May 6 14:38 ..
-rwxrwxrwx 1 pi www-data 131072 Apr 4 07:04 robotAI.sqlite
So if the file /home/pi/robotAI/static/sqlite/robotAI.sqlite is owned by the www-data group, and has permissions of rwx at the group level then why cant I access it or see it as www-data? I have rebooted several times.
-
Just to be sure www-data was in the www-data group I also ran "sudo usermod -a -G www-data www-data". But this did nothing.Lee Melbourne– Lee Melbourne2017年05月06日 05:14:53 +00:00Commented May 6, 2017 at 5:14
2 Answers 2
Looks like the directory that you try to list only has 771 permissions (user and group can read/write, others can't), and its group is pi
. Try the chmod
/chown
without the -R
flag to set the permissions of the directory itself.
-
I actually made the directory and file both owned by www-data user AND group. Yet things still do not work. Does every directory in the chain need to be owned by the user? This is ridiculous, as it has worked in every build I have done previously.Lee Melbourne– Lee Melbourne2017年05月06日 22:44:57 +00:00Commented May 6, 2017 at 22:44
-
Copied the file locally to /var/www/html and set owner as www-data and group as www-data and set permissions as 777. Now NGINX can read the file, but cannot write to the file. This all makes no sense. I am going to re-build the Pi.Lee Melbourne– Lee Melbourne2017年05月06日 23:13:38 +00:00Commented May 6, 2017 at 23:13
-
A bit late but have you tried restarting it?trillian– trillian2017年05月07日 06:40:26 +00:00Commented May 7, 2017 at 6:40
Rebuild of pi sorted it and the usual permissions i set worked fine. Very annoying.
-
Please accept your answer. This is the only way to finish the question and it will never pop up again for years.Ingo– Ingo2019年12月01日 12:49:25 +00:00Commented Dec 1, 2019 at 12:49