Used to switch the current user identity to another user identity
su command is used to switch the current user identity to another user identity. When changing, you must enter the user account and password to be changed.
su(option)(parameter)
-c<command> or --command=<command>: After executing the specified command, the original identity will be restored;
-f or --fast: applies to csh and tsch, so that the shell does not need to read the startup file;
-l or --login: When changing the identity, the working directory, as well as HOME, SHELL, USER, and logname will also be changed at the same time. In addition, the PATH variable will also be changed;
-m, -p or --preserve-environment: Do not change the environment variables when changing the identity;
-s<shell> or --shell=<shell>: Specify the shell to be executed;
--help: display help;
--version; display version information.
User: Specify the target user to switch identities.
Change the account to root and exit back to the original user after executing the ls command:
su -c ls root
Change the account to root and pass the -f
option to the newly executed shell:
su root -f
Change the account to test and change the working directory to test's home directory:
su-test