To switch users in one terminal session, you could use the su command :
$ whoami
firstuser
This shows the current user.
$ su – seconduser [linux change user]
Password:
Switching to the second user.
$ whoami
seconduser
This shows the second user as the current user.
Read: How to create a Sudo user on Ubuntu
You do not need to specify a username, If you want to login as root :
$ whoami
firstuser
Current user is firstuser.
$ su – [change user linux]
Password:
Switching to root.
$ whoami
root
root is currently the active user.
Read: How to use sudo without having to enter a password in Ubuntu
In general, you can rely on sudo to start a new shell as the user you like.The -u option allows you to specify your desired username:
$ whoami
firstuser
$ sudo -u seconduser zsh
$ whoami
seconduser
If you do not have sudo access, there are some other alternative ways, like ssh username@localhost. The sudo command is rather simple to use as long as it is installed and you have the required permission to use it.
If you like the content, we would appreciate your support by buying us a coffee. Thank you so much for your visit and support.