What is the function of su command in linux system
What is the purpose of the su command in a linux system? I believe that many inexperienced people are at a loss about this, so this article summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
When we execute su with root, the su command creates 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 to, while the root shell process still exists, and vice versa, this is the reason for your question, because the previous user's shell process has not been closed, you can use exit to exit, you can see Instead of logging out, I went back to the previous user. Because they are parent-child processes, the end of the child process certainly does not affect the execution of the parent process. But if we forcibly kill the parent process, we just quit.
In fact, many people do not understand the difference between whoami and whoami, their roles are different.
Who am i displays the actual user ID of the current shell process.
Whomai displays the valid user ID for the current shell process.
In many cases, the two outputs are the same, so much 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
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
Yunhw@yunhw-Aspire-4750G:~$ whoami
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
As soon as the order was carried out, it withdrew completely.
After reading the above, have you mastered the function of the su command in the linux system? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!