Centos su command

Source: Internet
Author: User

Many Commands can only be executed as root, so we need to become a root user. To do this, we can use the su command (replacing users ). The su command has the following format:

Su-<user>
Or
Su <user>
But we usually use the su command to become the root user:
Su-Root
Or
Su Root
If the user name is not specified, the default user is root. Therefore, the preceding command can be shortened:
Su-
Or
Su
However, these two commands have different features. 'Su <user> 'grants the <user> identity to the current user, while 'Su-<user>' grants the <user> identity to the current user, set the environment to the <user> logon environment. In many cases, the user will simply use 'su 'to become the root user, attempt to execute a command (for example, ifconfig), and then receive an error of 'COMMAND not found. For example:
Su
Password:
Ifconfig
Bash: ifconfig: Command not found
The reason is that common users in the system have different path environment variables than root users. When you enter a Linux Command, the command shell will try to find and execute the command in the user's path. It searches for each directory in the PATH variable until matching is found.
Most of the time, when users report problems in IRC or other places, they will be directed to this page. When you want to check why an execution file cannot be found, it is helpful to view the existing path: Echo $ path

Most commands set for common users are in/usr/bin and/bin, occasionally, the/usr/local/bin -- upstream does not use the/usr/local/* path by default during packaging. However, most root commands are located at/usr/sbin and/sbin, and occasionally at/usr/local/sbin. This is also reflected in the root path.

When you use Su-to change to root, you will also adopt the root path. In contrast, only su will retain the user's path value. For this reason, when Su is used as the root, executing commands in/usr/local/sbin/,/usr/sbin, or/sbin will cause the command not found error. For more detailed explanations, see the bash User Manual (man bash), especially for the invocation and logon command shell section.

Therefore, if you only use Su, you need to provide the full path of the command (for example,/sbin/ifconfig). Otherwise, use Su-to become the root.
---------------------
Walking programmers
Source: csdn
Original: 16973481
Copyright Disclaimer: This article is an original article by the blogger. For more information, see the blog post link!

Centos su command

Related Article

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.