Switch Users in Linux Terminal using Su and Sudo Command


Updated on:

Switch users in Linux allows you to access and work within another user’s environment without need to logout and login back again.

The Linux operating system offers a command-line interface known as the terminal, which provides advanced users with powerful control and flexibility over their system.

Linux administrators frequently perform user management, which includes switching between different user accounts seamlessly.

This capability is particularly useful in multi-user environments, where different individuals require separate accounts to perform their tasks securely.

Switch Users in Linux

Types of Users in Linux

In Linux, there are different types of users with specific roles and permissions. Understanding these user types is little bit difficult for managing user accounts effectively for the security and stability of the system. The types of users in Linux is given below.

  • System Users – System users are created to run specific system services or applications. These accounts are usually used to manage system resources, run background processes, and handle various system tasks.
  • Superuser (root) – The superuser, also known as root, it is the most privileged user on a Linux system. Root has unrestricted access to all files, directories, and commands.
    • It has the power to modify system configurations, install software, and perform critical system tasks.
    • Due to its immense privileges, it is recommended to use the root account sparingly and only when necessary to avoid accidental system damage.
  • Regular Users – Regular users are the standard user accounts created for individual users. These accounts have limited permissions and access rights compared to the superuser.
    • Regular users can perform everyday tasks, run applications, access their home directories, and modify files they own. They do not have permission to modify system files or perform administrative tasks.
  • Guest Users – Guest users are temporary accounts created for non-authenticated or occasional users.
    • These accounts provide restricted access and limited functionality, guests can perform basic tasks without compromising the system’s security or personal data.
    • Guest accounts are typically reset after each session, erasing any modifications made during the user’s session.
  • Service Accounts – Service accounts are user accounts specifically created for running services. These accounts are dedicated to individual services or applications.
    • Service accounts usually have limited permissions and may have additional restrictions on their usage.

Also Check: Sudo Command in Linux – How to Use and Examples

How to Switch User in Linux using Su and Sudo Command

To switch users in the Linux using the su or sudo command, follow the below steps.

  1. Open a terminal window.
  2. For su command type the following command and press enter.
    • su – username
  3. For sudo command type the following command and press enter.
    • sudo -i -u username
  4. Replace “username” with the actual username of the user account.
  5. Enter your password correctly.
  6. Access to the user account. The terminal prompt will change to reflect the new user.
  7. You can now perform commands and operations as the switched user.
  8. To return to the original user account, you can type Exit or press Ctrl+D.

Note that when using the su or sudo command without specifying a username, it will switch to the superuser account (root) by default.

Is there any graphical way to switch users in Linux system?

Yes, most Linux distributions provide graphical interfaces such as GNOME, KDE, or XFCE that include a user switching functionality.

Can I switch users without knowing the password of the target user?

No, switch to another user account using the su or sudo command, you need to know the password of the target user.

Can I switch to a user account that is currently logged in?

No, you cannot switch to a user account that is already logged in.

How can I check the current user in the Linux terminal?

You can check the current user by typing whoami in the terminal and pressing Enter. It will display the username of the currently logged-in user.

Leave a Comment