How to Switch Users in Linux Terminal

Linux offers an independent, alternative method of switching users from other operating systems. The Linux SU command is the most excellent tool for accomplishing this. You might be wondering how to swap users in Linux via the command line if you’re new to the operating system.

You may easily switch your current user by using the “su” command. The su command for Linux switch users will be demonstrated in this post.

Types of Users in Linux

The root user of the superuser has complete control over the whole system. This account has full administrator rights and can manage other user accounts besides system-level operations like installing software and changing system files. When utilizing the root account, care must be taken to prevent unintentional system harm.

Switch Users in Linux Terminal
Switch Users in Linux Terminal

How to Switch User in Linux using ‘su’ Command

The superuser (root) is the default choice for ‘su’, if no username is supplied. Simply add the required user to the ‘su’ command syntax by finding it. ‘su’ should be typed into a command line as shown below to utilize it:

su [options] [username [arguments]]

You can type the following to show a list of commands:

su –h

Listed below are a few popular su command options:

Username –The username should be changed to the specific username you wish to use to log in. Any user, not only root, may perform this.

–c or –command [command] runs a certain command under the given user’s account.

– or –l or –login [username] –runs a login script to switch to a certain username.  For that user, a password must be entered.

–s or –shell [shell] –gives you the option to run in a different shell environment.

–h or –help – The su command’s help file should be shown.

–p or ––preserve–environment –Ensure the shell environment (HOME, SHELL, USER, and LOGNAME) is preserved.

Run the following commands to change the user logged in to this terminal window:

su –l [other_user]

A password will be requested from you. When you enter it, the login will now be for that user.

The root account will be used if a username is not provided. The logged-in user can now execute all system commands. Additionally, the home directory and path to executable files will change as a result.

Using the -c argument will allow you to run a command as a different user:

su –c [command] [other_user]

The system will request your user password in response.

The system will execute the ls (list directory contents) command using the provided account when you enter this example.

Use the following to switch to a new operating environment or shell:

su –s /usr/bin/zsh

The root user account is opened in the Z shell by this command.

How to Switch User in Linux using Sudo Command

You may use the sudo -i or sudo su - commands to swap users on Linux.

Your Linux computer should now open a terminal. Likewise, enter after you type the upcoming command:

sudo -i 


sudo su -

You can switch between the root user and the superuser with any of these commands, provided you have the required rights.

Your password must be entered when prompted. Enter your password once you’ve typed it. No characters will appear on the screen when you write the password for security purposes. Simply input it and press Enter.

You will change to the root user or superuser after a successful login. Using the root user account in the terminal is now possible.

  1. In Linux, how can I go from root to user?

    Su – or su username are commands that can change the current user’s username. While logging your activities (allowing you to track any changes made to the system by you or others), the sudo command allows you to behave as root.

  2. How do I sign in to Linux as a user?

    You may easily switch your current user by using the “su” command. The su command for Linux switch users will be demonstrated in this post. After that, you will be asked for that user’s password. You’ll be logged in as that person as soon as you enter.

  3. How can I use sudo to perform a command as a different user?

    According to the settings in /etc/sudoers, sudo runs commands under the identity of another user. This file must first be set to let a user run a command as another user. Additionally, while using sudo, the user authenticates with their own password rather than the user who wants to run the task.

*Disclaimer: The Content we produce on this page will be only such as advice or readable information. We provide the content on the page after getting it from different sources at that time. Still, the changes from time to time, like contact information such as phone numbers, email IDs, web links and any other about that product in any form, are not responsible to us. We provide the information you need and are not an authentic source. You may refer to the original/official website/page for further clarification and more info on that product.