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:
Options:
Option | Description |
---|---|
-c | Command to execute |
-l | Simulate a full login |
-m | Simulate a full login |
-s | Shell to use (default /bin/sh) |
Parameters:
Parameter | Description |
---|---|
username | The user to switch to |
su Usage:
Switch to Root User
This command allows you to switch to the root user by entering the root password.
Change to Another User
Used to switch to another user account by specifying the username.
Launch a Shell as Another User
Opens a shell as another user with their environment settings.
Switch User with Specific Shell
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:
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:
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:
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:
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:
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:
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:
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