Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What's the difference between su and su-in the linux command

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the linux command in su and su-what is the difference, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

To put it simply, su or su-are used to switch users in the following format

Su [-] username

Switch to root without username

The difference between the two is that su only switches the user identity, but the shell is still the original user, and the environment variables that belong to the original shell are still in effect. Sometimes we find that we have clearly switched users, but some commands still cannot be executed, just because although the users have switched, the environment variables are still those of the previous users.

It's useless to talk about it, last chestnut.

I have two users, user1 and user2, whose environment variables are different.

First, let's take a look at their respective environmental variables.

User1

$echo $PATH

/ usr/local/java/jdk1.8.0_161/bin:/usr/local/java/jdk1.8.0_161/jre/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/usr/local/mysql/bin

User2

User2@iZ2ze82p1dogvdrx4fu0i7Z:~$ echo $PATH

/ home/user2/bin:/home/user2/.local/bin:/usr/local/java/jdk1.8.0_161/bin:/usr/local/java/jdk1.8.0_161/jre/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games

Let's first use the su command to see the effect.

User2@iZ2ze82p1dogvdrx4fu0i7Z:/home/user1 $su user1

Password:

User1@iZ2ze82p1dogvdrx4fu0i7Z:~$ echo $PATH

/ usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games

User1@iZ2ze82p1dogvdrx4fu0i7Z:~$

As you can see, after switching to user1, the environment variable printed is still user2.

Then use su-compare and see the effect.

User2@iZ2ze82p1dogvdrx4fu0i7Z:~$ su-user1

Password:

$echo $PATH

/ usr/local/java/jdk1.8.0_161/bin:/usr/local/java/jdk1.8.0_161/jre/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/usr/local/mysql/bin

$

Obviously, the environment variables have also been switched over.

Thank you for reading this article carefully. I hope the article "what's the difference between su and su in linux commands" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report