How to automatically switch to home directory when switching user?

5,746

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
Share:
5,746

Related videos on Youtube

Admin
Author by

Admin

Updated on September 18, 2022

Comments

  • Admin
    Admin over 1 year

    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?