ubuntu switch user code example

Example 1: change user linux

sudo su - username

Example 2: linux switch user

$ whoami
user1
$ su - user2
Password:
$ whoami
user2
$ exit
logout

Example 3: change ubuntu username

# To manage every aspect of the user database, you use the usermod tool.
# To change username (it is probably best to do this without being logged in):

sudo usermod -l newUsername oldUsername
# This however, doesn't rename the home folder.
# To change home-folder, use

sudo usermod -d /home/newHomeDir -m newUsername

Example 4: switch user ubuntu

$ su - user2