e-raser
Posts: 71
Joined: Sat Apr 04, 2015 1:30 pm

Linux permissions problem - create files (goaccess, nginx)

Tue Apr 07, 2015 8:13 pm

Hi,

it seems I have a little "typical" linux permissions problem. Freaked me out for almost 2 hours already. Maybe you can help me here (didn´t find a better matching area on the forum).

What I want to do: Use "goaccess" for parsing nginx webserver logs.

Problem:
Manual command "sudo -u www-data /usr/local/bin/goaccess -p /var/www/.goaccessrc -f /var/log/nginx/access.log > /var/www/owncloud/logs/ahd.htm" gives "bash: /var/www/owncloud/logs/ahd.htm: no rights"
So the user www-data can´t write the .htm file (same result with "sudo -u www-data touch /var/www/owncloud/logs/test.txt"). Same with user pi, even with sudo!

I created the logs-folder manually and used "sudo chown -R www-data:www-data /var/www/owncloud/logs" for changing the owner to www-data. I also tried a chmod with 777 on the directory - nothing changed.

Owner of the folder is already www-data:

Code: Select all

drw-r--r-- 2 www-data www-data 4096 Apr 6 20:30 logs
Question: What can I do for giving www-data access to read+write to the logs-folder? I already tried several chown and chmod commands, but I simply don´t get it... really really frustrating.
Last edited by e-raser on Tue Apr 07, 2015 8:46 pm, edited 2 times in total.
1x Nextcloud & Pi-hole & ... on Raspbian @ Pi (4 4 GB)
1x Kodi media center on LibreELEC @ Pi 3 B+

User avatar
DougieLawson
Posts: 36578
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Linux permissions problem - create files (goaccess, ngin

Tue Apr 07, 2015 8:45 pm

If it's a directory you need rwx to create new files.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

e-raser
Posts: 71
Joined: Sat Apr 04, 2015 1:30 pm

Re: Linux permissions problem - create files (goaccess, ngin

Tue Apr 07, 2015 8:47 pm

What would be the right chmod command for changing it?
"sudo chmod ??? /var/www/owncloud/logs" ?
1x Nextcloud & Pi-hole & ... on Raspbian @ Pi (4 4 GB)
1x Kodi media center on LibreELEC @ Pi 3 B+

User avatar
DougieLawson
Posts: 36578
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Linux permissions problem - create files (goaccess, ngin

Tue Apr 07, 2015 9:25 pm

e-raser wrote:What would be the right chmod command for changing it?
"sudo chmod ??? /var/www/owncloud/logs" ?
sudo chmod 755 /var/www/owncloud/logs
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

e-raser
Posts: 71
Joined: Sat Apr 04, 2015 1:30 pm

Re: Linux permissions problem - create files (goaccess, ngin

Wed Apr 08, 2015 7:14 am

Same result! Seems it´s a bit more complicated...
1x Nextcloud & Pi-hole & ... on Raspbian @ Pi (4 4 GB)
1x Kodi media center on LibreELEC @ Pi 3 B+

e-raser
Posts: 71
Joined: Sat Apr 04, 2015 1:30 pm

Re: Linux permissions problem - create files (goaccess, ngin

Wed Apr 08, 2015 7:25 am

No chance. My ownly workaround at the moment is writing the .htm file to e.g. /home/pi and doing "sudo -u www-data cp /home/pi/ahd.htm /var/www/owncloud/logs/ahd.htm".

It´s really freaky...
1x Nextcloud & Pi-hole & ... on Raspbian @ Pi (4 4 GB)
1x Kodi media center on LibreELEC @ Pi 3 B+

User avatar
rpdom
Posts: 15601
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Linux permissions problem - create files (goaccess, ngin

Wed Apr 08, 2015 7:45 am

e-raser wrote: Owner of the folder is already www-data:

Code: Select all

drw-r--r-- 2 www-data www-data 4096 Apr 6 20:30 logs
Question: What can I do for giving www-data access to read+write to the logs-folder? I already tried several chown and chmod commands, but I simply don´t get it... really really frustrating.
sudo chmod 775 logs
or
sudo chmod g+w logs

User avatar
jojopi
Posts: 3088
Joined: Tue Oct 11, 2011 8:38 pm

Re: Linux permissions problem - create files (goaccess, ngin

Wed Apr 08, 2015 8:27 am

e-raser wrote:Manual command "sudo -u www-data /usr/local/bin/goaccess -p /var/www/.goaccessrc -f /var/log/nginx/access.log > /var/www/owncloud/logs/ahd.htm" gives "bash: /var/www/owncloud/logs/ahd.htm: no rights"
Shell redirections (">") are set up before the command ("sudo") is started. This error means that pi cannot write the file, not www-data. (In fact user www-data would not require access at all. Permissions are needed at the time of opening, not the time of writing.)

Of course the main problem is that the directory lacks execute permission, but as well as that you will need either the clumsy:

Code: Select all

sudo -u www-data bash -c "command > file"
Or, perhaps more sensibly, add user pi to group www-data and make the directory group-writeable so that both users have access.

e-raser
Posts: 71
Joined: Sat Apr 04, 2015 1:30 pm

Re: Linux permissions problem - create files (goaccess, ngin

Wed Apr 08, 2015 8:30 am

Same result (no rights). I almost gave up and used the following workaround as cronjob:

/usr/local/bin/goaccess -p /var/www/.goaccessrc -f /var/log/nginx/access.log > /var/www/goaccess.html; mv /var/www/goaccess.html /var/www/owncloud/logs/index.html

BUT - UPDATE:
I think I found the mistake.

After

Code: Select all

sudo chmod 755 /var/www/owncloud/logs
when using the cronjob the command

Code: Select all

/usr/local/bin/goaccess -p /var/www/.goaccessrc -f /var/log/nginx/access.log > /var/www/owncloud/logs/index.html
worked perfectly.

So I checked the same command on bash with "sudo -u www-data ..." --> error again.
So I was wondering if the whole command really was processed as www-data: I put an "...; whoami" at the end, which gave "pi"... so the error was (or is) that the command on bash was not run as www-data. Would be interesting to know the correct syntax; i thought "sudo -u username command" is the right one.

At the end not a permission issue, more a "bash sudo as another user" one.
1x Nextcloud & Pi-hole & ... on Raspbian @ Pi (4 4 GB)
1x Kodi media center on LibreELEC @ Pi 3 B+

e-raser
Posts: 71
Joined: Sat Apr 04, 2015 1:30 pm

Re: Linux permissions problem - create files (goaccess, ngin

Wed Apr 08, 2015 11:41 am

jojopi wrote:
e-raser wrote:Manual command "sudo -u www-data /usr/local/bin/goaccess -p /var/www/.goaccessrc -f /var/log/nginx/access.log > /var/www/owncloud/logs/ahd.htm" gives "bash: /var/www/owncloud/logs/ahd.htm: no rights"
Shell redirections (">") are set up before the command ("sudo") is started. This error means that pi cannot write the file, not www-data. (In fact user www-data would not require access at all. Permissions are needed at the time of opening, not the time of writing.)

Of course the main problem is that the directory lacks execute permission, but as well as that you will need either the clumsy:

Code: Select all

sudo -u www-data bash -c "command > file"
Or, perhaps more sensibly, add user pi to group www-data and make the directory group-writeable so that both users have access.

Thanks, didn't read your post before my update.
1x Nextcloud & Pi-hole & ... on Raspbian @ Pi (4 4 GB)
1x Kodi media center on LibreELEC @ Pi 3 B+

Return to “Raspbian”