What is the usage of the Linux sudo command?
The sudo command is used to execute commands as a superuser, meaning to run commands with the root user’s permission. It allows regular users to temporarily gain administrator privileges when needed to carry out administrative tasks.
The basic usage of the sudo command is:
Use the command with administrative privileges.
Popular options include:
- -u: Specify which user identity to execute the command.
- Use the environment variables of the target user.
- -s: Execute the command using the shell of the target user.
- – Keep the environment variables and do not clear them by using sudo.
For example, to execute the apt-get update command as an administrator, you can use the following command:
sudo apt-get update
When running the sudo command, you will be prompted to enter the password for the current user. After entering the password, if the authorization is successful, the corresponding command will be executed with administrator privileges.