Home » Linux Host, Ubuntu, SysAdmin » Linux Commands » Switching users with the su command

Switching users with the su command

The su command in Unix-like operating systems, including Linux, is used to switch to another user account or to execute commands with the privileges of a different user, typically the superuser (root).

Here’s a basic overview of using the su command:

Switching to the superuser (root):

To switch to the superuser account, you can simply type:

$ su

If prompted, you’ll need to enter the root password. After successful authentication, you will have the privileges of the root user.

Switching to a specific user:

To switch to a specific user, you can use:

$ su username

Replace “username” with the username of the account you want to switch to. If you don’t specify a username, it defaults to the superuser (root).

Running a command with elevated privileges:

You can also use su to run a specific command with elevated privileges without switching to a different user interactively. For example:

$ su -c "command_to_run"

Replace “command_to_run” with the command you want to execute with elevated privileges.

Exiting from the superuser or another user:

To exit from the superuser or another user and return to your original user account, you can type:

$ exit

This will return you to the original user’s shell.

Using sudo as an alternative:

On many Linux distributions, the sudo command is commonly used for command execution with elevated privileges. Instead of switching to the root user using su, you can use sudo to run specific commands with elevated privileges:

$ sudo command_to_run

You will typically be prompted to enter your user password when using sudo.

Note: The availability and behavior of the su command can vary between different Unix-like systems and distributions. Some systems may require configuration to allow certain users to use su, and the root password may be required. Additionally, some systems use alternatives like sudo for granting temporary elevated privileges. Always follow security best practices and use caution when using superuser privileges.


Subscribe our Rurban Life YouTube Channel.. "Rural Life, Urban LifeStyle"

Leave a Comment