What is the command that can convert a normal user to a super user in linux

08-01-2023

What is the command that can convert ordinary users into super users in this Linux? For reference, I hope you can gain something after reading this article. Let’s take a look at the command that can convert ordinary users to super users in this Linux article.

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 is used to switch to another user's identity to execute the command, the syntax is sudo -s or sudo -i.

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

There are two commands in Linux to convert ordinary users to super users:

  • su command

  • sudo command

Linux temporary switch user identity (su command)

su is the simplest user switch command, through This command can switch any identity, including switching from normal user to root user, switching from root user to normal user, and switching between normal users.

Switching between ordinary users and switching from ordinary users to root users requires knowing the password of the other party. Only by entering the correct password can the switch be realized; switching from the root user to other users does not need to know the other party The password can be directly switched successfully.

The basic format of the su command is as follows:

su [options] username

Options:

  • -: The current user not only switches to the identity of the specified user, but also switches the working environment to this user's environment (including PATH variable, MAIL variable, etc.), use the - option to omit the user name, it will switch to the root user by default.

  • -l: Similar to the use of -, that is, while switching the user identity, the work environment is completely switched, but you need to add the switch to user account.

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

  • -m: Same as -p;

  • -c command: only switch users to execute the command once, after execution Automatically switch back, the option is usually followed by a command to execute.

Example: Convert normal user to superuser

$ su -root

< /p>

sudo command

We know that using the su command can allow ordinary users to switch to root status to execute certain privileged commands, But there are some problems, for example:

Give normal users full authority to control the system just for a privileged operation;

When multiple people use the same host, if everyone If you want to use the su command to switch to the root status, you will inevitably need the root password, which leads to many people knowing the root password;

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

Compared to using the su command and requiring a new switch user password, the sudo command only needs to know its own password. Even, we can manually modify the sudo configuration file so that it does not require any password 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 new user account] command to be executed

  • sudo -s : The terminal environment has not changed after switching to root

  • sudo -i: The environment has also changed (more thorough switching)

If the sudo switch fails, modify the configuration file

If the switch cannot be switched as shown above, modify the configuration file under the root user

vi /etc/sudoers

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

Or add it under %sudo %rc (user group name) ALL=(ALL:ALL) ALL (add sudo permission to users in the group)

The above isI believe everyone has a certain understanding of the content of this article about the commands that can convert ordinary users into super users in Linux. I hope that the content shared by the editor will be helpful to everyone. If you want to learn more , please pay attention to Yisu cloud industry information channel.

Copyright Description:No reproduction without permission。

Knowledge sharing community for developers。

Let more developers benefit from it。

Help developers share knowledge through the Internet。

Follow us