Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
1. Command function
The role of SU is to change to the identity of other users, except the superuser, who needs to type the user's password.
2. How to use
su [-FMP] [-C command] [-s Shell] [--help] [--version] [-] [USER [ARG]]
3. Parameter description
-F, –fast: Do not need to read the boot file (such as CSH.CSHRC, etc.), only for CSH or tcsh two kinds of shell.
-L, –login: After this parameter is added, it is as if it were re-landed, most of the environment variables (such as home, shell, user, etc.) are based on the user, and
and the working directory will also change. If user is not specified, the default is root.
-M,-p, –preserve-environment: does not change the environment variables when performing su.
-C command: Change the user's username and execute the instruction (command) before changing back to the original user.
Help displaying the description file
–version Display version Information
User: To change the user account,
ARG: The new shell parameter is passed in.
4. Example
Su-c ls root changes the account number to root and exits to the original user after the LS command is executed.
Su [user name]
A> under root user, enter Su ordinary user. Switch to normal user, switch from root to work without requiring a password
B> under normal user, enter Su [user name]
Hint Password:
Enter the user's password, then switch to the user
Expand read one: Linux What is the difference between the lower su Command and the Su-command?
Su is switching to other users, but does not switch environment variables (for example, the Export command to see the difference between the two commands)
Su-is the complete switch to a user environment
So it is recommended that when you switch users, try to use su-linuxso so that you may find that some commands do not
Extended Reading II: The difference between Su and sudo
Because SU does not have the restriction of permissions after switching to Superuser root, SU does not act as a system managed by multiple administrators. If you use SU to switch to the Superuser to manage the system, it is not clear what work is done by which administrator. In particular, for the management of the server with many people involved in the management, it is best for each administrator's technical expertise and scope of management, and a targeted delegation of authority, and agreed on what tools they use to complete their work, then we need to use sudo.
Through sudo, we can put some super-privileged targeted decentralization, and do not need to know the root password of ordinary users, so sudo relative to the unrestricted permission of Su, is still relatively safe, so sudo can also be referred to as restricted Su, and sudo is required to license, So also known as the licensing of SU;
The process of sudo executing a command is that the current user switches to root (or the other user specified to switch to), executes the command as root (or another specified switch to the user), and then returns directly to the current user after execution is completed, which is premised on the configuration file of sudo/etc/ Sudoers to authorize;
Detailed usage of the SU command