Two different cases of su switching user identity-general Linux technology-Linux technology and application information. The following is a detailed description. Function Description: Change the user identity.
Syntax: su [-flmp] [-- help] [-- version] [-] [-c <指令> ] [-S] [User Account]
Note: su allows users to temporarily change their login identities. Enter the user account and password to be changed.
Parameters:
-C <指令> Or -- command = <指令> After the specified command is executed, the original identity is restored.
-F or -- fast is applicable to csh and tsch, so that the shell does not need to read the Startup File.
-.-L or -- when login changes its identity, the working directory, HOME, SHELL, USER, and LOGNAME are also changed. In addition, the PATH variable is also changed.
-M,-p, or -- preserve-environment do not change environment variables when changing identities.
-S or -- shell = specifies the shell to be executed.
-- Help: displays help.
-- Version: displays the version information.
[User Account] specifies the user to change. If this parameter is not specified, it is changed to root by default.
For the sake of simplicity, its usage is still pasted up. Enter the subject:
There are two scenarios for switching user identities: su username and su-username. The differences are described below.
Assume that you log on to the system as a normal user, but want to view the system network configuration information, you need to switch to the root user.
First case:
$ Su root: switch to the root user. The system will prompt you to enter the password. The switch is successful after the password is correct.
$ Ifconfig view network configuration information
However, after running the ifconfig command, the system prompts bash: ifconfig: command not found.
Case 2:
$ Su-root: switch to the root user. The system will prompt you to enter the password ( A horizontal line more than above)
$ Ifconfig view network configuration information
In this case, you can view the network configuration information for your real purpose.
Why? As we all know, some commands can only be used by administrators. Generally, users do not have permissions. like ifconfig in this example. the second method is used to switch the identity, which is equivalent to re-login. At this time, the user's home directory and PATH information will change, consistent with the direct use of root login; but in the first case, after switching to the root identity, the user's home directory and PATH are still the home directory and PATH of common users. We know that some paths are set in the PATH and point to some directories, these directories contain some common tools. if you do not set the corresponding PATH for your PATH, running the ifconfig system will certainly not find the ifconfig tool. therefore, you will be prompted: This command is not available.
I hope it will be helpful for beginners!
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service