Skip to content

Linux su command

The Linux su (substitute user) command is used to switch to another user account in the terminal without logging out. This command allows users to perform tasks with the privileges of a different user, such as the root user. By using su, users can execute commands that require higher privileges or access files owned by another user. It is an essential tool for system administrators to carry out administrative tasks securely.

su Syntax:

Terminal window
su [option] [username]

Options:

OptionDescription
-cCommand to execute
-lSimulate a full login
-mSimulate a full login
-sShell to use (default /bin/sh)

Parameters:

ParameterDescription
usernameThe user to switch to

su Usage:

Switch to Root User

Terminal window
su

This command allows you to switch to the root user by entering the root password.

Change to Another User

Terminal window
su username

Used to switch to another user account by specifying the username.

Launch a Shell as Another User

Terminal window
su - username

Opens a shell as another user with their environment settings.

Switch User with Specific Shell

Terminal window
su -s /bin/bash username

Switches to another user with a specific shell (/bin/bash in this example).

How do I use su in Linux?

To use the su command in Linux, execute the following command:

Terminal window
su --option <value>

How do I switch to root user using su in Linux?

To switch to the root user using the su command in Linux, use the following command:

Terminal window
su

How do I switch to a specific user using su in Linux?

To switch to a specific user using the su command in Linux, use the following command:

Terminal window
su <username>

How do I login as a different user shell using su in Linux?

To login as a different user shell using the su command in Linux, use the following command:

Terminal window
su -s <shell> <username>

How do I preserve the environment when switching users with su in Linux?

To preserve the environment when switching users with the su command in Linux, use the following command:

Terminal window
su - <username>

How do I specify the login shell to use when switching users with su in Linux?

To specify the login shell to use when switching users with the su command in Linux, use the following command:

Terminal window
su -s <shell> <username>

How do I execute a command as another user using su in Linux?

To execute a command as another user using the su command in Linux, use the following command:

Terminal window
su -c "<command>" <username>

Applications of the su command

  • Running commands with superuser privileges
  • Switching to another user account
  • Changing to a different user’s environment
  • Testing user permissions and access rights