Possible Duplicate:
How to apply changes of newly added user groups without needing to reboot?
I am on Ubuntu 11.04. I am creating another user and placing an existing user in the group of other user, hoping to write in the home directory of other user.
# uname -a
Linux vini 2.6.38-11-generic #50-Ubuntu SMP Mon Sep 12 21:18:14 UTC
2011 i686 athlon i386 GNU/Linux
# whoami
sachin
# su root
# useradd -m -U foo // create user foo
# usermod -a -G foo sachin // add user `sachin' to group `foo'
# chmod 770 /home/foo/
# exit
# whoami
sachin
# cd /home/foo/
bash: cd: /home/foo/: Permission denied
# groups sachin
sachin : sachin foo
This is totally weird. Though user sachin is in group foo, and group bits for /home/foo/ is set to rwx, sachin can't chdir to /home/foo/. I am not able to understand this.
But, if at the exit step, I switch to sachin user from root, this is what happens:
# uname -a
Linux vini 2.6.38-11-generic #50-Ubuntu SMP Mon Sep 12 21:18:14 UTC
2011 i686 athlon i386 GNU/Linux
# whoami
sachin
# su root
# useradd -m -U foo // create user foo
# usermod -a -G foo sachin // add user `sachin' to group `foo'
# chmod 770 /home/foo/
# su sachin
# whoami
sachin
# cd /home/foo/
# ls
examples.desktop
Now, whatever is happening here is totally incomprehensible. Does su sachin inherits some permissions from the root user at this step?
A solution that was suggested was to use newgrp
, which updates the group and other user information. So if I do newgrp - sachin
, then I get access to the directory of the newly created user, but if I create one more user and follow the same steps sachin
does not get access to the latest users directory.
This behavior is indeed very baffling.
Any explanations would be much appreciated.
sudo
instead of running as root. Some tools depend upon being run as sudo, not root. And to add users to groups in Debian-derived distros, use theadduser
wrapper. – dotancohen Jun 17 '12 at 12:37sudo
runs the given command as root...it is considered bad form to give the root account a password, tough. – Bobby Jun 17 '12 at 14:37