Linux is a multiuser operating system where a single computer can be used by multiple users with multiple accounts. A user can change the current user into another user or root user via a command-line interface or GUI. In this tutorial, we examine different ways to change users in Linux.
Change User Using su Command
The su command allows commands to be run with a substitute user or group. A username can be provided to the su command in order to change to the provided user. In the following example, we change to the user
$ su ismail
When the su command is called with the username, the specified user password is asked in order to change to that user. After providing the user password the specified user shell is opened.
The current user can be checked by printing the
$USERNAME shell variable which displays the current user for the bash.
$ echo $USERNAME
Change User Using sudo Command
sudo command is the most popular command to change users in Linux. The
-u option is used to specify the user we want to change to. In the following example, we change to the user
$ sudo -u ismail
Alternatively, we can change the user for a single command. The provided command is executed as the provided user and its privileges. In the following example, we change the user for the
passwd command to the
$ sudo -u ismail passwd
Change User To root Account
Sometimes we may need to change the user
root . The root user is the administrator user for most of the Linux distributions and it has high-level privileges to change the Linux system. The
su command can be simply used like below to change into the root account easily.
$ sudo -
Change User Using GNOME GUI
GNOME is a Linux desktop environment that provides a very nice GUI with related tools. The Gnome can be also used to change the current user by logging out and logging in as a different user. First on the upper right corner click to the
Power Off/Log Out and then click to the
In the following screen click to the
Log Out to log out completely.