Learning from the differences between Su and SU on the Linux operational dimension method

Source: Internet
Author: User
Tags rsync egrep

Old boy Linux training new class just beginning, the old boy found in the group is discussing this Su and Su-difference, some students say, direct Su can, some say must Su-. Some students ask directly, in the end Su and Su-what is the difference?

1 The answer to "fish"

6.6.1.3 su Command instance

When the SU command is executed without any parameters, it indicates that you want to switch to the root user, but you may experience problems with this execution. Because although it is switched to root user, but did not change to the root user login environment, the user's default login environment, can be found in the/etc/passwd, including home directory, Shell type and so on. The more canonical way of doing this is "Su-". See the example below.

Instance 1: Switching from normal user Oldboy to root user

[Oldboy@oldboy ~]$ WhoAmI #→ confirms that the current user is Oldboy

Oldboy

[Oldboy@oldboy ~]$ su #→ is cut to root without a user. Of course, you can also use the SU root.

Password: #→ This is, of course, the root user's password.

[Root@oldboy oldboy]# Env

Hostname=oldboy

User=oldboy

Mail=/var/spool/mail/oldboy

Pwd=/home/oldboy

Home=/root

Logname=oldboy

... Omit partially irrelevant content ...

#→ attentive readers should have seen that, if the use of Su without "-" This parameter, then the user before switching the relevant information will still exist, which will cause a lot of trouble, and even unexpected results. Therefore, it is best to "Su-username" when switching users. This is the standard way of switching users in a production scenario.

[Root@oldboy oldboy]# exit #→ exits the current user, this command can also be replaced with the Ctrl+d shortcut key command.

[Oldboy@oldboy ~]$ Su-#→ with the "-" parameter to switch, also available Su-root command. This is the standard operating method in the production scenario.

Password:

[Root@oldboy ~]# Env|egrep "user| mail| pwd| LOGNAME "#→ The result of the environment variable information after switching. Use Egrep to filter the rows that contain the string you want to view.

User=root

Mail=/var/spool/mail/root

Pwd=/root

Logname=root

#→ this is different from the last time, all environment variable information has been switched to root. Therefore, please switch users must add "Su-user name", here to remind, not only cut to root yo, switch to other users is the same, hehe.

SU Command Summary:

1 Normal user switch to root user, can use Su-or su-root. You must enter the root password to complete the switch.

2 The root user switch to the normal user, you can use the "Su-ordinary user name" to the wording. You do not need to enter any password to complete the switch. When you switch to a normal user, you may encounter an environment variable path path problem and cannot find some system commands (typically the following commands,/sbin,/usr/sbin, etc.) when you execute commands such as ifconfig, and then you need to move the normal user's path Configured as root path content, the previous article has explained this configuration method, the unclear reader, can read down.

3 You can use the Su-username-C command If you only want to execute a command under a user without switching directly to that user.

The above excerpt from the old boy Linux Training Lectures and book lesson notes section.

Old boy commented: Although this is good for students to explain, but this is still the way to teach the fish, students must be aware of how they can obtain such knowledge, and not easy to ask the teacher to obtain, only learned to learn the method and self-study ability is to learn Linux Yun-dimensional relatively high realm, but also the future development of the road.

2 The answer to "fishing"

1 can go to search engines, and then according to say to practice, and finally don't forget to summarize.

This is "fishing", but not completely, that is not to learn the good idea of Linux operation, but a lot of beginners by default will be so (but the search skills are scarce), so, this road is OK, but the best is the following thought.

2 to understand the difference between Su and Su, in fact, is to know the role of Su, Su-such a command is obviously-is SU parameters, so you can completely man su or su--help get the answer you want, and then, In the help of the above lesson plan tips to practice knocking on the experience (don't forget to summarize good notes).

The man su or Su--help is as follows:

SU parameter options

Note Note (with ※ The presentation is important, need to master)

-,-L,--login

Make the shell a login shell

#→※ makes a shell a landing shell, such as executing Su-oldboy, indicating that the user wants to change identity as Oldboy, and uses the Oldboy user's environment variable configuration, such as:/home/oldboy/.bash_profile, etc.

[Oldboy@student ~]$ su--help
USAGE:SU [OPTION] ... [-] [USER [ARG] ...]
Change the effective user ID and group ID to that of user.
-,-L,--login make the shell a login shell
... Omitted part ...
[Oldboy@student ~]$ man Su
NAME
Su-run a shell with substitute user and group IDs
Synopsis
Su [OPTION] ... [-] [USER [ARG] ...]
DESCRIPTION
Change the effective user ID and group ID to that of user.
-,-L,--login
Make the shell a login shell
... Omitted part ...

The process of practice is very important, see above.

Extension: For example, the old boy has published a blog exam question

1. How to obtain the/etiantian file's rights corresponding to the digital content, such as-rw-r--r--644, requires the use of the command to obtain 644 such figures.

The answers are as follows:

http://oldboy.blog.51cto.com/2561410/791638

This problem is a good example of developing learning thinking and self-study ability. When the command result contains the content we need, we have to think whether the command has specific parameters that can achieve the desired result in one step.

Emphasis on learning methods of learning, is to learn the way of Linux Yun-Wei, this is also the old boy writing a blog rarely published some services to the deployment process to everyone or specific business scripts, because the old boys think these are given to the "fish" method, should be as far as possible to avoid or must be combined with a variety of methods, fully granted to the "fish" effect is relatively small. Therefore, the "fishing" process is basically in the old boys to leave the students after the Homework section completed, the old boy said "fishing", the students to the teacher "fish."

Add an old boy after class to ask everyone to hand in the catch "fish":

Tip: Since the students learn how to catch fish skills, we must let the old boy see the fishes: The following is required to be handed over to catch fish:

The old boy training for the 15th time after the class shell homework:

(Face-to-face classes according to the summary of individual distribution, network classes are all written)

Please all students must complete, fishing skills are not old boy said you will, must have many times to grasp the practice, students refueling, there will not be the problem after class discussion or consult a mentor.

1) Lnmp One-click installation Script <==zhengdong

Requirements: Linux centos5.8,nginx1.3.4,mysql5.5.27,php5.3.17

2 Linux System One-click Optimization Script <==chenya

3 Lamp One-click installation Script <==zhangji

4) rsync,sersync,inotify One-click Installation and Configuration Script <==sanyapen

5 MySQL multi-instance installation and backup script <==zhangxian

6) Apache,nginx,mysql,rsync service detection and Monitoring script <==yanggongwan

7 MySQL master-slave synchronization one-key implementation script <==fengyiwe

8 Lamp One-click installation Script <==lifen

This article is from the "Old boy's Linux blog" blog, please be sure to keep this source http://oldboy.blog.51cto.com/2561410/1053606

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.