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 are the differences between sudo and su in linux

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article introduces the relevant knowledge of "what are the differences between sudo and su in linux". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Differences: 1, sudo is a root user to execute commands, su is used to change the identity of other users to execute commands; 2, sudo can skip root login to execute some specific commands, only need to provide the current user password, while su can not skip root login, must provide root user password.

The operating environment of this tutorial: linux7.3 system, Dell G3 computer.

What is the difference between sudo and su in linux

What is su?

The full name of su is not super user, but switch user. Do you suddenly understand? It means to switch users. The general use of su is su or su -, although the difference between the two methods is only 1 character, but there is a big difference.

The-parameter is added, which is the way of login-shell, that is, after switching to another user, the current shell will load the corresponding environment variables and various settings

If the-parameter is not added, it is the way of non-login-shell, that is, the current shell is still loading the environment variables and various settings of the user before the switch.

If you don't want to make your settings under the current user unavailable because you switch to another user, you can use non-login-shell; if you need to use various environment variables of that user after switching to another user, you can use login-shell.

The usage of su

The su (English spelling: switch user) command is used to change the identity of another user.

Example:

(1) su # switches to the root user by default, enters the root password to switch the root user, and finally executes the exit command to switch to the original user

The password here is not displayed by default. The following figure switches from song user to root user

When entering exit, switch to the original user

(2) su (user name to be switched)

Switch from root user to song user Note: you don't have to enter a password to switch from root to another user

Suppose that if there are many people managing this host, it is not that many people need to know the password of root, and some people may only operate it once, then the way of su is not very good at this time. Of course, the less people know the password of root, the better, and the less people know, the more secure it will be. At this time, you need another way. You need to use sudo.

What is sudo?

The full name is super user do, that is, the command is executed as a super user. The super user here refers to the root user. We sometimes encounter the situation of permission denied in Linux, such as viewing the content of / etc/shadow as a ubuntu user, because it can only be viewed by root users. Sudo can be used at this time.

The difference between the two is:

Use su-provide the password of the root account, you can switch to the root user

Use sudo su-to provide the password of the current user, or you can switch to the root user.

If our Linux system has a lot of users to use, the former requires all users to know the password of root users, which is obviously very dangerous; the latter does not need to expose the root account password, users only need to enter their own account password. And which users can switch to root is entirely under the control of root (root is implemented by setting / etc/sudoers), so the system is much safer.

This is the end of the content of "what is the difference between sudo and su in linux". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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

Servers

Wechat

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

12
Report