The su command is used to switch to another user identity.
If "user" is ignored when su is used to switch identities, the system switches to the "root" identity by default and requires a password. When switching from the root user to another user, you do not need to enter the password. Otherwise, you need to enter the password of the corresponding user.
If the-or-l or -- login parameter is added to a new user, the current Shell environment is switched to the new user's Shell environment, which is equivalent to logging on to the new user from the console.
Lab:
Use su and su to switch user identities.
1) view the current directory with pwd: the directory of the new user is not displayed when su switches to the new user.
Su-switch to the new user and display the directory of the new user.
2) use set to view environment variables
Common User
Switch su to root:
Su-switch to root. At this time, the shell environment variables are changed to the root environment:
The above three items show that the UID is changed during the su switch, but the user and username are not changed. When the su-switch is used, all the environment variables are changed to the new user.
32.16touchfile: permission, owner, and group of abc.txt.
If you have wx permission on a folder, you can perform write, rm, touch, vi, and cat operations on the folder's files.
Su switches to the root user and creates the abc file. The owner and group of abc are both root.
4) use echo $ PATH to export the PATH
When a common user exports PATH,
When su switches to root, export PATH,
When su-switches to root, export the PATH
The contents of the three paths are different.
Therefore, the PATH issue does not occur only during su-switching. "Command not found"