How to switch users in Linux

October 31, 2024 / How-to Guide

Switching users in Linux allows you to change from one user account to another without logging out of the current session. This can be useful for performing administrative tasks or accessing files that belong to a different user.

Here are several methods to switch users in Linux:

Method 1: Using the ‘su’ Command

  1. Open the Terminal: You can do this by searching for “Terminal” in your applications menu.
  2. Switch User: Type the following command, replacing the username with the actual username you want to switch to:
    su - username
  3. Enter Password: You will be prompted to enter the password for the specified user. After entering the password, you will be switched to that user’s account.

Method 2: Using the ‘sudo’ Command

  1. Open the Terminal.
  2. Switch User: To switch to another user with administrative privileges, use:
    sudo su - username
  3. Enter Your Password: You may need to enter your password, not the password of the user you’re switching to.

Method 3: Using the ‘login’ Command

  1. Open the Terminal.
  2. Switch User: You can switch users using the login command as follows:
    login username
  3. Enter Password: Enter the password for the user you want to switch to.

Method 4: Using ssh for Remote User Switching
If you are accessing a remote system, you can switch users by connecting via SSH:

  1. Open the Terminal.
  2. SSH into the System: Use the following command:
    ssh username@hostname
  3. Enter Password: Enter the password when prompted to log in as that user.

Tips:

  1. If you want to return to the original user session after switching, type exit in the terminal.
  2. Ensure that the user you are switching to has permission to access the terminal.
    Use the whoami command to check the user who is currently logged in.

By following these methods, you can easily switch between user accounts in Linux, enabling you to perform various tasks efficiently.

Spread the love