Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am member of couple of groups lets say Master, Student, Web. The problem is that by default whatever I do is first created under student group. I need to set it so it is created with Web group.

Folder www/ where I need to write file is already mode 770. But because it picks up my student group it does not allow me to write to that folder.

Is there any way to change the group that I create files under.

If I execute groups it lists all groups so I am member of correct group I just cant write to the folder.

Anyone?

share|improve this question

4 Answers 4

If you do 'id', you'll see your primary group, listed as something like gid=1000(student). By default, all files will be created with that group.

However, that is not your problem. If you are a member of a group which has write permission to a directory, then you can create a new file.

Are you sure that the permissions on www is correct? Do 'ls -ld www'.

share|improve this answer

Are you sure you're in the correct web group? On Ubuntu this probably means running usermod -a -G www-data yourname alternately, www might have incorrect permissions. Make sure it's set so that group members have read/write access: chmod -R 770 /var/www.

share|improve this answer

If you want to permanently change the user's default group, use usermod (manpage):

# set "web" as the primary group for user "username"
$ sudo usermod -g web username

Or, you can put newgrp web (or whatever the group name is) in your .bashrc, somewhere near the end of the file, to get "logged into" the Web group each time you login -- without changing your user's primary group. newgrp (manpage) sets the "effective group ID". Watch:

# what's my current effective GID?
$ id -g
1000

# "login" to another group 
$ newgrp www-data

# now what's my effective GID?
$ id -g
33
share|improve this answer

Unless there's something unusual about Ubuntu, if you make the permissions on the target directory 'SGID', then all files created in the directory will belong to the group that owns the directory:

chmod g+s /var/www

Now all files under /var/www will, by default, be created with the 'web' group that (I assume) owns the directory.

MacOS X defaults to this behaviour even if the SGID bit is not set on the directory.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.