Switch to current home user directory after switching user in Ubuntu
I created a new user on my Linux machine with the following commands
sudo useradd -m foo.bar
sudo passwd foo.bar
After that, I switch to foo.bar
, but the current directory does not direct to the current user and the info of the current user does not show in the command line
ubuntu@ip-172-31-47-200:~$ su foo.bar
Password:
$
$ whoami
foo.bar
$
$ pwd
/home/ubuntu
I would like to have something like
foo.bar@ip-172-31-47-200:~$
How can I achieve this?
Solution 1:
what you're looking for is the flag '-l'. You can directly access a users home-directory + initialize path-variables etc. by using "su -l user", where user is the username you're logging in with.
More information: su man-page