The example of the su command in Linux explains

  

The su command under Linux is mainly used to switch users. It can switch between ordinary users and super users. What are the uses of the su command? After using the su command, are other users still there? Let's take a look at the examples of the su command under Linux with the Xiaobian.

original Q: linux, I log in as root, and other users to log in and use the su command to switch to root user, what is there not the same, if the same thing, I execute su command after the other Users are still not in the system? I am trying to delete other users after executing su, linux prompts, other users logged in? Why

Answer: Let me explain it to you! In the Unix system, when the user logs in, a shell process is created for each user, providing interactive functions. If you are using bash, then the shell process is bash, ksh is used, the process is ksh, and other shells are the same.

For the process, in its process PCB (process control block), there are two values ​​of the actual user ID and the effective user ID. The so-called actual user ID refers to the identity of the process. For example, I am currently the root user. The actual user ID of the process I created is the root ID, which is usually 0. The effective user ID refers to the ID of the user who currently has the right to use the process. For example, if I have a car, I will group it out. The owner of this car is me, but the permission is not mine.

In general, the actual user ID and the valid user ID are the same. The su command has such a function that a process can run with the permission of the command owner, that is, the actual user ID of the process can be made. The valid user IDs are not the same. You can use ls -l to view the su command. It must be written as s (small s) on its owner's x permission bit. The passwd command is the same, they have the same function. This s bit means that the user who executes the command can execute with the owner's permission of the command. If you cancel the s bit, only the owner of su can su.

Now let's explain it further, I hope you can understand it.

When we execute su as root, the su command will create a new shell process with the current shell process as the parent process. This shell process is provided to the user we want to su, and root. The shell process still exists, and vice versa, this is the reason you asked the question, because the previous user's shell process has not been closed, you can use exit to exit, you can see, not logout, Instead, go back to the previous user. Because they are the relationship between the parent and child processes, the end of the child process will of course not affect the execution of the parent process. But if we forcefully kill the parent process, we will quit directly.

In fact, many people do not understand the difference between whoami and who am i, their role is different.

who am i Displays the actual user ID of the current shell process.

whomai displays a valid user ID for the current shell process.

Many times, the two outputs are the same, so that we think the two commands have the same effect.

Example: root@yunhw-Aspire-4750G:~# who am i

root pts/0 2011-12-10 13:13 (:0.0)

root @yunhw-Aspire-4750G:~# whoami

root

root@yunhw-Aspire-4750G:~#ps -ef

root 2939 2935 0 13:18 pts /0 00:00:00 bash

root@yunhw-Aspire-4750G:~# su - yunhw

yunhw@yunhw-Aspire-4750G:~$ who am i

root pts/0 2011-12-10 13:13 (:0.0)

yunhw@yunhw-Aspire-4750G:~$worami

yunhw

root@ yunhw-Aspire-4750G:~#ps -ef

root 2939 2935 0 13:18 pts/0 00:00:00 bash

yunhw 2958 2939 0 13:19 pts/0 00 :00:00 su - yunhw

yunhw 2966 2958 7 13:19 pts/0 00:00:00 -su

root@yunhw-Aspire-4750G:~#sudo kill -9 2939

Once this command is executed, it will be completely quit.

The above is the usage of the su command under Linux. The su command is used to explain the specific usage of the problem. It also gives a reference to the users who have encountered the problem. Have you learned? ?

Copyright © Windows knowledge All Rights Reserved