Which command in Linux can convert an ordinary user into a super user?

青灯夜游
Release: 2022-09-19 17:44:27
Original
23167 people have browsed it

Two commands to convert an ordinary user into a super user: 1. The su command can switch any identity. You need to know the password of the root user. The syntax is "su -root"; 2. The sudo command, use To switch to another user's identity to execute commands, the syntax is "sudo -s" or "sudo -i".

Which command in Linux can convert an ordinary user into a super user?

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

There are two commands to convert an ordinary user into a super user in Linux:

  • su command

  • sudo command

Linux temporarily switches user identity (su command)

su is the simplest user switching command, through which you can Realize any identity switching, including switching from ordinary users to root users, from root users to ordinary users, and between ordinary users.

To switch between ordinary users and to switch from ordinary users to root users, you need to know the other party's password. Only by entering the password correctly can you switch; switching from root user to other users does not require knowing the other party's password. , the switch can be successful directly.

The basic format of the su command is as follows:

su [选项] 用户名
Copy after login

Options:

  • -: The current user is not only switched to Specify the identity of the user, and the working environment used is also switched to the user's environment (including PATH variables, MAIL variables, etc.). Use the - option to omit the user name, and it will be switched to the root user by default.

  • -l: The use of - is similar, that is, while switching the user identity, the working environment is completely switched, but the user who wants to switch needs to be added later. account.

  • -p: Indicates switching to the identity of the specified user, but does not change the current working environment (the switching user's configuration file is not used).

  • -m: Same as -p;

  • -cCommand: only switch users Execute the command once and automatically switch back after execution. This option is usually followed by the command to be executed.

Example: Convert ordinary user to super user

$ su -root
Copy after login

Which command in Linux can convert an ordinary user into a super user?

Which command in Linux can convert an ordinary user into a super user?

sudo command

We know that using the su command allows ordinary users to switch to root identity to execute certain privileged commands, but there are some problems, such as :

Directly grant full permissions to ordinary users to control the system just for a privileged operation;

When multiple people use the same host, if everyone wants to use the su command to switch to the root identity, That will inevitably require the root password, which leads to many people knowing the root password;

Considering the hidden dangers that using the su command may cause to system installation, the most common solution is to use the sudo command. This command It also allows you to switch to the identity of another user to execute commands.

Compared with using the su command, which requires a new user's password, running the sudo command only requires knowing your own password. Even, we can manually modify the sudo configuration file so that it does not require any password. Ready to run.

The sudo command can only be run by the root user by default. The basic format of the command is:

sudo [-b] [-u 新使用者账号] 要执行的命令
Copy after login
  • sudo -s: Switch to the root terminal The environment has not changed

Which command in Linux can convert an ordinary user into a super user?

  • sudo -i: The environment has also changed (the switch is more complete)

Which command in Linux can convert an ordinary user into a super user?

If sudo switching fails, modify the configuration file

Which command in Linux can convert an ordinary user into a super user?

If the switch cannot be performed as shown above, the configuration file must be modified under the root user

vi /etc/sudoers
Copy after login

As shown below: add rc ALL=(ALL:ALL) ALL (add sudo permissions to user rc)

Or add %rc (the name of the user's group) under %sudo ALL=(ALL:ALL) ALL (Add sudo permissions to users in the group)

Which command in Linux can convert an ordinary user into a super user?

Related recommendations : "Linux Video Tutorial"

The above is the detailed content of Which command in Linux can convert an ordinary user into a super user?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!