Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”
1. The su command
Su, switch user, is the command used to change the identity of a user. When using the su command to switch the user identity, you need to verify the new identity, that is, enter the password to switch to the user.
1.1 Su command expression
su [-] <username>
Copy the code
-
Su: You can run the su command without any parameters, that is, the default status of parameters. By default, the system runs the su root command to switch to user root and enters the password of user root for authentication
-
Su root: su command followed by the user name to switch to the specified user. If there is a password, you need to verify the password
-
Su – root: Run the – command to switch to the specified user. If there is a password, you need to verify it
1.2 su root
和su - root
The difference between
If you run the su command without an argument, you will run the su root command. If you run the su root command, you will run the su – root command.
-
: If this option is used, the command is switched to the specified user in login-shell mode. After the switch is complete, the environment variable is updated to the new user
You can run the PWD command to view the current user path to check whether the environment variable has changed
-
The PWD information is not updated after the su root command is used to switch users
-
Run the su – root command to switch the user. The PWD information is updated to the new user Settings and the login information is displayed
2. The sudo command
Sudo, or super user do, is used to execute commands as a super user. It is important to note that su and sudo are completely different in meaning.
2.1 Expression of the sudo command
Sudo [option] [command]Copy the code
The user is not in the sudoers file. This will be reported. If the user is not in the sudoers file, this will be reported.
-
Sudo [-i/-] root: This command is also used to switch the current user to the root user. However, unlike the su command, the password of the previous user needs to be verified
-
Sudo su: This command is the longest used to run Linux commands. It is used to run related commands with the highest permission. The essence of this command is to raise the su command.
3. Differences in the use of the two
The differences with the su and sudo commands can be summarized as follows
- The su command is switch user, which is used to switch the user. When switching the user, you need to provide the password of the user to be switched
- The sudo command is super user do, which is used to upgrade the command permission and switch users. Before using the command, you need to authenticate the password of the current user. When executing the sudo command, the user must have certain permissions