Get 50% Discount Offer 7 Days


Contact Info

Chicago 12, Melborne City, USA

+88 01682648101

[email protected]

Recommended Services
Supported Scripts
Tutorial Switch Users in Ubuntu 20.04

In this article, we are going to teach you How to Switch Users in Ubuntu 20.04. Linux is a multi-user operating system and it allows more than one user to log in and perform operations without affecting other users of the system. For this reason, we decided to explain to you how to switch between users in 3 ways. Follow us in the continuation of this article.

How to Switch Users in Ubuntu Linux

There are various ways to switch users. These methods include:

1) Switch Users from Graphical Environment

2) Switch Users from su Command

3) Switch Users from the SSH method

In the following, we will teach each of these methods.

1- Switch Users from Graphical Environment

In the first step on Ubuntu, you should click on the Power icon in the top bar. Then select “Log Out” or “switch user” from the drop-down menu. This option may not be available in some versions.

drop down menu logout ubuntu 20.04

_ If you select the “Log Out” option, you will navigate to the login window to specify the username and password of your desired user.

_ If you select the “Switch User” option, you can specify the username and password of the user when your session preserve and all your running processes.

Note that if you do not have access to the “Switch User” option, you must press CTRL+ALT+F2, which takes you into a shell prompt. By doing this you can specify your username and password. You must enter CTRL+ALT+F2 to revert.


2- Switch Users from su Command

This helps both preserve the current session and switch to another user. If the root user does not log in via GUI session or SSH, the su command will be useful for it. To do this enter  the following command:

$ su [OPTIONS] [-] [USER [args]]

When the above command is invoked without a specified username, the shell runs as root, which enables a password for the root user.

If you use the su command without options, the current working directory will not change to /root.

Two options or -l is the most commonly used su commands. With the help of the -l option, su will be possible to change the home directory and a shell session similar to real-login will be spawned that is set in /etc/passwd.

How to Use su Command to Switch to a Different User

You can use the -l option to log in as a different user followed by the user’s username. Consider the following example:

$ su -l ubuntu

After entering the above command, you will be asked to enter the password. Then you will enter the specified user.

How to USe su Command to Log In with a Different Shell

By default, the environment variables expressed in the /etc/passwd file are used in su. These options include the default shell. However, with the -s option, you can change the login shell. Like the following command:

$ su -l ubuntu -s /bin/bash

The ubuntu user is launched with the bash shell by the above command.

How to Use su command while preserving the environment

You can use -p or –preserve-environment to execute the user with the su command while preserving the environment variables. For example, use the following command to log in as an Ubuntu Neuronvm user while preserving the environment variables:

$ su -p neuronvm

How to USe su Command to run a Command as a Different User

Using the -c option, you can run a command as a different user without creating an interactive shell session:

$ su -c top

3- Switch Users from SSH method

Another way to change the users on Ubuntu 20.04 is SSH. You can log in to the local user using the following command:

$ ssh [email protected]

Switch Users from SSH method


A su user is a great tool for switch users or executing commands as another user. You can set a specific user with su. In this article, you learned how to switch users on ubuntu 20.04 with 3 different methods.

5/5 - (1 vote)
Share this Post

Leave a Reply

Your email address will not be published. Required fields are marked *