How to switch users in Linux

By Angus Published 11 February 2025 Updated 4 March 2026 4 min read

Switching users in Linux allows you to access different accounts without logging out of your current session. This is necessary when you need to perform administrative tasks, test user permissions or access files owned by different accounts.

You will learn three methods for switching users: sudo su for administrative access, su for direct user switching and login for local systems. Each method serves different scenarios depending on your access level and requirements.

Before you begin

  • You need SSH access to your Linux server.
  • For sudo methods, your account must have sudo privileges.
  • For su methods, you need the target user’s password.

Check your current user

Before switching users, you can verify which account you are currently using. This helps confirm successful switches and prevents accidental changes to the wrong account.

  1. Open your terminal.
    Connect to your server via SSH or open a local terminal window.
  2. Run the whoami command.
    Type whoami and press Enter. The output displays your current username.
Terminal window showing the whoami command output displaying the current username
The whoami command confirms your current user account.

You can now switch to a different user account using one of the methods below.

Switch users with sudo

The sudo su command switches users using your own password rather than the target user’s password. This method requires sudo privileges on your account and is commonly used for administrative tasks.

  1. Open your terminal.
    Connect to your server via SSH if you have not already done so.
  2. Run the sudo su command.
    Type sudo su username, replacing username with the target account name. Press Enter.
  3. Enter your password.
    When prompted, type your own password (not the target user’s password). The system authenticates your sudo privileges.
  4. Verify the switch.
    Run whoami to confirm you are now operating as the target user.

This method is useful when you need temporary access to another account without knowing their password. You can now perform tasks as the target user or switch to a different account.

Switch users with su

The su command switches users by authenticating with the target user’s password. This method works without sudo privileges but requires you to know the password of the account you are switching to.

  1. Open your terminal.
    Connect to your server via SSH if you have not already done so.
  2. Run the su command.
    Type su username, replacing username with the target account name. Press Enter.
Terminal window showing the su command being used to switch to the root user account
The su command switches users after password authentication.
  1. Enter the target user’s password.
    When prompted, type the password for the account you are switching to. The system authenticates and switches your session.
  2. Verify the switch.
    Run whoami to confirm you are now operating as the target user.

This method is useful for testing user permissions or diagnosing access issues. You can now perform tasks as the target user or return to your original account by typing exit.

Switch users with login

The login command provides a full login session for the target user. This method is typically used on local systems or multi-user environments rather than remote servers.

  1. Open your terminal.
    Access a local terminal on your Linux system.
  2. Run the login command.
    Type login username, replacing username with the target account name. Press Enter.
  3. Enter the target user’s password.
    When prompted, type the password for the account you are switching to. The system creates a new login session.

This method is not supported on our VPS platform but may be available on local systems or other server environments. You can now work within a full login session as the target user.

Wrapping up

You can now switch between Linux user accounts using sudo su, su or login commands. Each method serves different scenarios: sudo su for administrative access without the target password, su for direct switching with password authentication and login for full login sessions on local systems.

After switching users, you may need to check file ownership to verify access permissions or change file ownership with chown if adjustments are required. Our VPS management guide covers additional server administration tasks.

Need more power?

Get scalable resources with our VPS hosting with root access and optional software.

Get VPS Hosting

Starting something new?

Perfect for websites and small businesses unlimited bandwidth with cPanel hosting.

Get cPanel Hosting