Linux operating system allows multiple users to perform tasks on a system without affecting the other users. Every user has a separate home directory and login name, which is not accessible to other users. The administrator can manage and create multiple users to grant them specific privileges. Somehow, the administrator may have to switch between numerous users to have some specific privileges. So, it’s an essential administrative task to switch users in Ubuntu 22.04.
This post will demonstrate multiple ways to switch users in Ubuntu 22.04. The post’s content is as follows:
Let’s get started!
Method 1: Switch User Using CLI
In this section, we will switch the user via the terminal. The “su” command is used to switch users in Ubuntu, To switch users in Ubuntu, the “su” command is used. The general syntax of the “su” command is as follows:
$ su [options] [-] [<user> [<argument>]]
Example: Switch a User
There can be multiple users in a system; we can switch the user within the system with the “su”command. To change the current user to a user named “Peter”, run the below-mentioned command:
$ su peter
The output shows that the user is immediately switched to the new user after executing the command.
To verify whether the user is switched or not, the “whoami” command may be used:
Example: Switch to a Different User as Login User
If you want to start a shell as a login shell, that means you will log in as another user but uses the rights (sudo, etc..…) of the login user. It will change the Home directory of the new user and also initializes the environment variables. The command provided below will switch the user to “peter”:
$ su -l peter
The above screenshot shows the switching has been successfully performed.
Method 2: Switch User Using GUI
To switch the user using the GUI approach, we need to log out from the current session and log in with a different user. To do so, the process is described below:
Click on the “Power” icon at the top left (Adjacent to the Volume icon). It will show a list of options; now click on the “Power Off/Log Out” button, which will open a dropdown list. Choose the “Switch User” option to sign out:
It will log you out of the current session and redirect you to the “Start” window of Ubuntu 22.04 where you can find all the users in the system. Click on the desired one and then :
Now, you can switch the user and log in again.
That’s all from this guide!
The GUI and CLI methods are used to switch users in Ubuntu 22.04. In the command line method, use the “su <user-name>” command to switch users. Moreover, to switch users as login users, you may use the “su -l <user-name>” command. Apart from that, the GUI method is also demonstrated to switch users in Ubuntu 22.04. This post has demonstrated a list of methods to switch users in Ubuntu 22.04.