Difference between su and su-in CentOS command line

Source: Internet
Author: User

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"


Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.