Home >System Tutorial >LINUX >Use and differences of Linux commands su, sudo, sudo su, sudo -i

Use and differences of Linux commands su, sudo, sudo su, sudo -i

WBOY
WBOYforward
2024-02-05 19:06:031446browse

The main differences between sudo and su commands are:

The sudo command requires the password of the current user to obtain permissions, while the su command requires the password of the root user. Additionally, their default behavior is different. The sudo command only allows a single command to be executed with elevated privileges, whereas the su command starts a new shell and allows multiple commands to be executed with root privileges until you explicitly log out.

Linux命令su、sudo、sudo su、sudo -i使用和区别

su is used to switch to different user identities:

Linux命令su、sudo、sudo su、sudo -i使用和区别

By default, only the identity is switched, and the environment variables are not switched. The environment variables are still those of ordinary users. When switching user identities, the user's environment variables are also switched to the new user's environment variables, so "-" cannot be omitted, otherwise some operations cannot be performed.

su root After entering the root password, switch to the root user but the pwd directory remains unchanged

Linux命令su、sudo、sudo su、sudo -i使用和区别

su – root Enter the root password and switch to the root user but the pwd directory/root

Linux命令su、sudo、sudo su、sudo -i使用和区别

sudo usually adds the command

sudo -i root has the same effect as sudo - root, sudo -i, sudo -, sudo root. When prompted to enter a password, the password is the password of the current account. The user who executes the command must be in sudoers. What su needs is The password usage of the account after switching is "su account name"

sudo: Temporarily switch to super user mode to execute super user privileges, generally refers to the root user. When prompted to enter a password, the password is the password of the current user, not the password of the super account. However, there is a time limit. Ubuntu defaults to a 15-minute session.

su: Switch to a certain user mode and when prompted to enter a password, the password is the password of the account after the switch, and the usage is "su account name". If no account is added later, the system defaults to the root account, and the password is also the password of the super account. no time limit.

sudo -i: In order to frequently execute certain permissions that only the super user can execute without having to enter a password every time, you can use this command. When prompted for a password, the password will be the password for the current account. no time limit. After executing this command, the prompt changes to "#" instead of "$". When you want to return to a normal account, you can execute "exit" or "logout". The user who executes this command must be in sudoers

Linux命令su、sudo、sudo su、sudo -i使用和区别

sudo -i Directly run the sudo command and add the -i parameter. The user who executes the command must be in sudoers

Linux命令su、sudo、sudo su、sudo -i使用和区别

sudo su Run the sudo command to elevate the su command and run the su command. The user who executes this command must be in sudoers.

The above is the detailed content of Use and differences of Linux commands su, sudo, sudo su, sudo -i. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:lxlinux.net. If there is any infringement, please contact admin@php.cn delete