Article Title: Use sudo to grant root permissions to common users. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
In general, root permissions are inseparable, so it is difficult to give a user the power to complete a task, such as backup, without giving the user the freedom to run the system. It is obviously unsafe to give root to multiple users.
SUDO is widely used to solve this problem.
The so-called SUDO is to log on to the system as a common user. When a task needs to be completed (assuming that the common user is not authorized to use this task), the task is completed with the administrator root authorization. Oh, by the way, it's a bit like a delegate in WINDOWS. Once authorized, users can do things they cannot do, so as to help administrators manage and reduce the burden on administrators.
When sudo is executed, it reads the/etc/soduers file, which lists the persons authorized to use sudo and the commands they can run on each host. If the command provided to sudo is allowed to run, sudo prompts you to enter your own password and execute the command. If you use sudo again within the next five minutes, you do not need to enter a password. Sudo does not have a defined log file, so if you want to use sudo logs, You have to configure it yourself. We will discuss how to configure it later.
If you want to configure the sudo file, we recommend that you configure the/etc/sudoers file using the mongodo file. It will check whether someone is editing and modifying the file at the same time. The following is an example:
# Host Aliases Host_Alias FILESERVERS = fs1, fs2
Host_Alias MAILSERVERS = smtp, smtp2 # Networking
Cmnd_Alias NETWORKING =/sbin/route,/sbin/ifconfig,/bin/ping,/sbin/dhclient,/usr/bin/net,/sbin/iptables, /usr/bin/rfcomm,/usr/bin/wvdial,/sbin/iwconfig,/sbin/mii-tool # Allow root to run any commands anywhere
Root ALL = (ALL) ALL Tom, z3 FILESERVERS = ALL Jerry MAILSERVERS =/usr/sbin/tcpdump: FILESERVERS = (L4) DUMP W5ALL = (ALL) ALL ,! SHELLS |
The first part is used to define the host. If not, you have to manually write data in the third part. The second part is used to define the service. If it is not defined, You have to manually write data in the third part. We recommend that you use this alias to define your "operations", which makes sudoers more readable.
The third part is the definition of permissions, that is, who can use sudo to do things. The format is as follows:
Applicable users should pay attention to the host = (to whom the identity is converted) What command can be used
If the content in the brackets is not defined, the operation is performed only as root .! Indicates "".
When a common user, such as tom, logs on to the system to perform operations that are not permitted to be performed, he can enter the following command:
Sudo su?
Then, enter your own password.
AliasMainly divided4Type
Host_Alias
Cmnd_Alias
User_Alias
Runas_Alias 1)ConfigurationHost_Alias: Indicates the host list.
Host_Alias HOST_FLAG = hostname1, hostname2, hostname3
2)ConfigurationCmnd_Alias: Indicates the list of commands that can be executed.
Cmnd_Alias COMMAND_FLAG = command1, command2, command3
3)ConfigurationUser_Alias: HasSudoList of authorized users
User_Alias USER_FLAG = user1, user2, user3
4)ConfigurationRunas_Alias: The identity of the user (for exampleRoot, OrOracle).
Runas_Alias RUNAS_FLAG = operator1, operator2, operator3
5)Configure permissions The permission configuration format is as follows:
USER_FLAG HOST_FLAG = (RUNAS_FLAG) COMMAND_FLAG If password verification is not required, configure it in this format.
USER_FLAG HOST_FLAG = (RUNAS_FLAG) NOPASSWD: COMMAND_FLAG |
Benefits of using sudo
1. Logs can improve the security audit capability.
2. The operator can complete many tasks without the unrestricted root privilege.
3. Ensure the security of the root password
4. Faster than su
5. Some permissions can be revoked without changing the root password.
6. You only need to maintain sudoers to maintain the list of user privileges.
7. reduce the probability of legacy root shell
8. You can use a single file to control access to the entire network.
Of course, there are also deficiencies. For example, if you break through the personal account that can execute the sudo command, it is equivalent to breaking through the root account itself.