Su usage instructions in Linux

Source: Internet
Author: User

1. Difference between Su and Su-

Log on to my fc6 system as a common user, use the su command to switch to the super user, and then enter the ifconfig command. The error "command not find" is returned. If you use the Su-command to switch to the Super User, and then enter the ifconfig command, the execution will be successful. This involves the difference between the su command and the Su-command. The help document obtained by Man Su is as follows:

-,-L, -- login make the shell a login shell
The translation is as follows:
-.-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.


Simply put, the su command will not change the current working directory and home, Shell, user, and LOGNAME. In addition, the PATH variable is changed, and the Su-command is changed to the root user by default. For example:
Enter:
$ Pwd
/Home/mgqw (current user directory)
$ Su
* ***** (Enter the password)
# PWD (view the path again)
/Home/mgqw (or the current user directory)

However, if you change to Su-, the result is as follows:
$ Pwd
/Home/mgqw (current user directory)
$ Su-
* ***** (Enter the password)
# PWD (view the path again)
/Root (switch to the superuser directory)

 

2. If the sh script executed by a root user needs to be executed by other users in some places, use the following method:

/Bin/su-switched user-c "executed command"

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.