Linux uses Su to switch users or specify users to execute commands

Time:2021-6-12

instructions

# su -h

Usage:
 Su [option] [-] [user [parameter]...]

Change the valid user ID and group ID to the ID of user. If user is not specified, the default is root.

Options:
 -, - L, - login switches the environment variables (home, shell, user, logname, path, etc.) at the same time. If it is not used, the temporary permission of the user will be obtained and the environment variables will not be loaded. After switching users with the Su command, you can use the exit command or the shortcut key [Ctrl + D] to return to the original login user
 -c. -- command < command > pass a command to the shell using - C
 -s. -- shell < shell > specifies the shell to be used, and the default is the value set in the / etc / passwd file

Use example:
su - admin -s /bin/sh -c "id"

The difference among runuser, Su and sudo

command Root to user User to root User to user Authentication method log file remarks
runuser Y N N nothing nothing Lower than su.
su Y Y Y The password of the target user /Var / log / auth.log or / var / log / secure Risk of root password leakage.
sudo Y Y Y Your own password /Var / log / auth.log or / var / log / secure Let the user run some (or all) of the commands as root.