Add users to sudoers in CentOS
In Ubuntu, General Accounts can execute commands as super users through the sudo command, as long as they enter the user's password. However, in CentOS, that is, when you create a user to install the system, the user has the Advance setting item. You can add the newly created user to the group. If this parameter is set to sudoer/sudoers, after logging on to the system and executing the sudo command, the system still prompts that the user does not exist in the sudoers group. In this case, we need to add the current user to the sudoers user group. 1. modify the permissions of the/etc/sudoers file 1. Because the owner of the/etc/sudoers file is root, the current permission of this file is
-r--r-----. 1 root root #440
2. to modify this file, you need to change its permissions to write permissions for other users, or switch to the superuser mode.
Switch User: directly switch to the root mode, and directly modify the file or modify the permissions: After modifying the permissions of the root identity, access with the current user identity.
2. Add a user to sudoers. 1. Find the user in the sudoers file.
Root ALL = (ALL) ALL # Next line feed and add the current user to xxx ALL = (ALL) ALL;
2. If you do not want to enter the password every time, you do not need to enter the password every time after modification.
xxx ALL=(ALL) NOPASSWD: ALL
3. revoke the permission on the/etc/sudoers file. If you modify the permission of the file to add users, You need to restore the permission attribute of the file after the file is added. 4. NOTE: If chmod 777/etc/sudoers is directly used for graph convenience during permission modification, the permission must be restored after the user is added, if the sudo command is not executed, the following error message is displayed:
sudo:/etc/sudoers is world writable sudo:no valid sudoers sources found ,quitting sudo:unable to initialize policy plugin
Run the following command to fix the problem:
Run chmod 440/etc/sudoers as root.