Table of Contents
This tip is about the how to Switch Users on Linux. So read this free guide, How to Switch Users on Linux step by step. If you have query related to same article you may contact us.
How to Switch Users on Linux – Guide
There are three types of accounts in Linux: system, user and root. A user logs into their Linux user account by entering their username and password. System processes, such as email, also log in to Linux when they are started. The root account is a special user account with unlimited privileges to perform any operation. Assuming you know the password of another account and the account allows user logins, you can switch users in Linux with the “su” command, commonly referred to as the “surrogate user”, “superuser” or “switch user” command .
Change user on Linux using su
The first way to change your user account in a shell is to use the su command.
$ su
For example, to log into the account named “john”, you would run the following command.
$ su john
Password:
[john@localhost user ~]$
As you can see, by not specifying the hyphen when running su, you inherit the environment variables of the account it’s coming from.
To verify this, try running the following command
$ echo $ USERNAME
of the user
To change the user by creating a new environment, you must su with a hyphen.
$ su – john
Password:
[john@localhost ~]$
Change user on Linux using sudo
Another way to change the current user is to use the sudo command.
By default, you will need privileged rights to run this command, so make sure you have sudo rights on Debian-based or Red Hat-based distributions.
Now that you have sudo, to change the user you must run this command
$ sudo -u
-s [john@localhost antoine~]$
As you can see, you also inherit environment variables when using this command.
To start a command as another user, you can also attach a command to the sudo command.
$ sudo -u
For example, to change a user’s password, you would run
$ sudo -u john passwdChanging user password johnCurrent password: New password: Retype new password: passwd: all authentication tokens successfully updated.
Change user to root account on Linux
In some cases, it may be necessary to change the current user to login as the root account.
To change the user to the root account, simply run “su” or “su -” with no arguments.
$ su – Password:[root@localhost ~]#
$ suPassword:[root@localhost user]#
Change User Account Using GNOME Interface
If you installed Debian or CentOS with a GNOME interface, you can also change the user account by following these steps.
To change the user using GNOME, find the power button in the upper right corner of the screen and click on it.
Click the username label and then click “Change User” to change the current user.
You will be redirected to the lock screen, where you can switch to any account you like.
Final note
I hope you like the guide How to Switch Users on Linux. In case if you have any query regards this article you may ask us. Also, please share your love by sharing this article with your friends.