I am running Ubuntu 10.04 server and am having some very counter-intuitive experiences with users/groups. For example:

# create empty file
sudo touch test_file

# create 'test' group
sudo groupadd test

# change group of file to 'test'
sudo chown root:test test_file

# give write permissions to group
sudo chmod g+rwx test_file

# add my user to 'test' group
sudo usermod -a -G test {my-user}

# touch the file as my current user
touch test_file

The last line produces a permissions error, however I have ensured that my user is part of the 'test' group (groups {my-user} confirms this). The group of test_file is also definitely set to 'test' and the group permissions are set. What am I missing?

link|improve this question

80% accept rate
feedback

2 Answers

up vote 3 down vote accepted

When adding a user to a new group, that won't be applied in any currently-running processes, only new ones. You need to log out and then log back in.

link|improve this answer
or hack su - username into your running console. you dont have to logout to login this way :) – mugen kenichi Jul 27 '10 at 23:21
feedback

You can use the newgrp command to change the user's current group ID. From man newgrp:

The newgrp command is used to change the current group ID during a login session. If the optional - flag is given, the user's environment will be reinitialized as though the user had logged in, otherwise the current environment, including current working directory, remains unchanged.

link|improve this answer
1  
This also has the effect of replacing your current group. It's not always a good idea. – Daenyth Jul 27 '10 at 23:09
feedback

Your Answer

 
or
required, but never shown

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