4

I've recently installed nginx on my dev machine with Ubuntu 12.04.

I am currently logged in as myuser and after installing nginx I setup the following file permissions (nginx www folder was owned by root so I wanted to change that so I can edit files with myuser):

# add myuser to nginx group sudo usermod -a -G www-data myuser # change ownership for www folder to nginx user (www-data) chown -R www-data:www-data /usr/share/nginx/www chmod -R 775 /usr/share/nginx/www 

Then I go to /usr/share/nginx/www and try to create a new folder/file. I always get Permission denied.

Here is a listing of the folder:

drwxrwxr-x 2 www-data www-data 4096 Apr 29 11:01 . drwxrwxr-x 3 www-data www-data 4096 Apr 29 11:01 .. -rwxrwxr-x 1 www-data www-data 383 Jul 7 2006 50x.html -rwxrwxr-x 1 www-data www-data 151 Oct 4 2004 index.html 

Everything seems to be fine here. The only thing weird I noticed is with the id command for myuser.

uid=1000(myuser) gid=1000(myuser) groups=1000(myuser),4(adm),20(dialout),24(cdrom),46(plugdev),116(lpadmin),118(admin),124(sambashare) 

As you can see the groups www-data (id=33) is not shown with id command. But if I try

id -G myuser 1000 4 20 24 33 46 116 118 124 

With the latest command the group id 33 is displayed for myuser, which makes me think this user is actually in the www-data group.

Does anyone has an idea why I cannot write in the /usr/share/nginx/www folder as myuser ?

1
  • try changing effective group for your shell newgrp www-data Commented Apr 29, 2012 at 11:59

1 Answer 1

3

In order to get www-data group permissions you need to change the effective group of myuser.

Issue

newgrp www-data 

and this should enable you to write in /usr/share/nginx/www.

It seems to me that the output of id will be updated (in Ubuntu) after you first change your group.

2
  • Thank you. That fixed my problem but unfortunately left me with a big question mark regarding file permissions in Unix :) Commented Apr 29, 2012 at 19:16
  • @user337620 Welcome! When every user acts from one group at a time, permissions are easy to check, since every file op carries on the user and group ids. If it were to check all groups the user belongs to, that would've required the system to look up the group file on every file op, essentially serializing all file operations... Commented Apr 29, 2012 at 19:23

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.