I am working on a CentOS release 6.9 linux distribution where my username is a member of two different groups: mygroup1 and mygroup2. If I am currently logged into an interactive shell using my primary group (mygroup1) and try to switch into my secondary group (mygroup2) using the command newgrp - mygroup2, my group does change, but the behavior of the change directory (cd ~) command does not bring me back to the mygroup2 home directory. Any idea why?

ssh user@host.com
id -ng
# returns: mygroup1
cd ~
# returns: /home/mygroup1/user
newgrp - mygroup2
id -ng
# returns: mygroup2
cd ~
# returns: /home/mygroup1/user (same as above, not mygroup2)

AFAIK, there is no such thing as a per-group home directory. When you do cd ~ you change to your user home directory which is usually set in /etc/passwd and does not depend on your group.

If you want to change your home, just do:

newgrp - mygroup2
cd ~              # Will move you to $HOME
  • Great thanks! It never occurred to me to simply change the HOME variable. – Todd Aug 23 '17 at 21:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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