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.
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.
If you need to buy a Linux VPS server, we suggest you to visit and use the various plans, with high quality and variety of locations offered on our website.
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:
_ 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 is preserved 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 to a shell prompt. By doing this you can specify your username and password. You must enter CTRL+ALT+F2 to revert:
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 command. 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.
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.
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.
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
Using the -c option, you can run a command as a different user without creating an interactive shell session:
su -c top
Another way to change the users on Ubuntu 20.04 is SSH. You can log in to the local user using the following command:
Switch users in Ubuntu 20.04 provide an effective way to manage multiple user accounts without the need for logging out or restarting the system. This comprehensive guide has explained various methods to switch users. With these techniques at your disposal, you can effortlessly switch between user accounts and optimize your productivity on Ubuntu 20.04.
How useful was this post?
Click on a star to rate it!
Average rating 5 / 5. Vote count: 1
No votes so far! Be the first to rate this post.
Apache Web Server is a modular web server that can have flexibility, power, and high performance on ...
What is your opinion about this Blog?