I just created a new user (I was logged in as root to do so) with the adduser utility. I gave the new user his own home directory. If I check the /etc/passwd file, it shows the users home folder is correct and even when I ssh into the server as that user it starts me off in the correct folder. However, whenever I type "cd ~", it takes me to /root. Anyone know how I can fix this?

link|improve this question

78% accept rate
feedback

5 Answers

There are a few things to check:

  • If you sudo to the new user using sudo -u <newuser>, make sure you pass the -H flag, so that it will set the HOME environment variable, like so: sudo -u <newuser> -H.
  • If you use su, make sure you use su - so that it will launch a login shell, which will explicitly set your HOME variable.
  • If you are logging in as this user from the get-go, you can verify that your home directory is set correctly in *sh by using echo $HOME to verify which HOME directory *sh THINKS you're using.

Hope these tips (and their explanations) help!

link|improve this answer
I was SSHing directly to the new user account. When the connection was made, It put me into the users home folder, but if I then typed "cd ~", it took me to /root. As for the other responses below, I wasn't su'ing into the user, I was logging in as the new user himself. I didn't check the uid of the user.. I didn't think two users could have the same uid? At any rate, our plans changed and I don't need this new user anymore, so it's been deleted. Thanks for all the suggestions though! – Safado Mar 28 '11 at 15:37
feedback

Did you log in as the new user? Or did you sudo over.

link|improve this answer
feedback

Did you log in as the user or did you su to the new user? If you used su, did you use su - or whatever the BSD equivalent is to make sure you use th new user's environment?

link|improve this answer
feedback

it's because youe euid is root. So you've done su or sudo to have root rights

link|improve this answer
feedback

Just to be sure, you did assign this user his own uid, and he's not using the same uid as root?

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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