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"