3

When i ssh to my ubuntu server, i get logged in to my user's home folder.

But when i do su otheruser and enter the password, i get logged in as the otheruser but the home directory stays for the previous user.

How to automatically switch to the logged user's home dir?

dsmsk80
  • 5,757
  • 17
  • 22
user2707590
  • 131
  • 1
  • 2

1 Answers1

12

Try to us su - otheruser command which starts the shell as a login shell with an environment similar to a real login:

  1. it clears all the environment variables except TERM
  2. it initializes the environment variables HOME, SHELL, USER, LOGNAME, and PATH
  3. it changes to the target user's home directory
  4. it sets argv[0] of the shell to '-' in order to make the shell a login shell
dsmsk80
  • 5,757
  • 17
  • 22