Introduction to the su Command
The su
command, short for "substitute user," is a powerful Linux utility that allows users to switch to another user account, typically the root or superuser account, to perform administrative tasks. This command is essential for system administrators and power users who need to execute commands with elevated privileges.
Understanding the su Command
The su
command is used to switch the current user to another user account. When executed without any arguments, it prompts the user to enter the password for the root user and then switches to the root account. This allows the user to perform tasks that require administrative privileges, such as installing software, modifying system configurations, or managing user accounts.
$ su
Password:
## ```
In the example above, the user has executed the `su` command, which has prompted them to enter the root password. After successfully authenticating, the user's shell prompt has changed to `#`, indicating that they are now operating as the root user.
### Switching to a Specific User Account
The `su` command can also be used to switch to a specific user account, rather than the root user. To do this, you can provide the username as an argument to the `su` command.
```bash
$ su - username
Password:
$
In this example, the user has executed su - username
, where username
is the name of the user account they want to switch to. After entering the correct password, the user's shell prompt changes to reflect the new user account.
Executing Commands as Another User
The su
command can also be used to execute a single command as another user, without switching the current user account. This is done by providing the command as an argument to the su
command, followed by the username.
$ su username -c "command"
Password:
In this example, the user has executed su username -c "command"
, where username
is the name of the user account and command
is the command they want to execute as that user.
By understanding the various use cases and options of the su
command, you can effectively manage user accounts and perform administrative tasks on your Linux system.