After adding a new account, we may find that the new account will report that it is not in sudoers when sudoing, and the authentication will fail after entering the password when using su -s
Most online searches require modification of the contents in /etc/sudoers, but modifying this file requires permissions, which leads to an infinite loop, so we need to change the strategy to change the file in a roundabout way:
1. Use another account with root permissions to log in, and then sudo -s to enter root mode
2. Check the /etc/sudoers file permissions. If the permissions are read-only, change them to write permissions
##3. Modify the /etc/sudoers file and execute the following command:
/*username is your username*/
[root@localhost ~]# echo 'username ALL=(ALL) ALL' >> /etc/sudoers
Or enter Visudo or vim /etc/sudoers with root permissions , find the field of root ALL=(ALL) ALL, append in the next line:
username ALL=(ALL) ALL
##For example, at this time You need to grant permissions to stu2:
##Then esc->:->wq save and exit
4. Restore the access rights of /etc/sudoers to 440
5, and then Log in to the new account to enter root
Note: If the authentication still fails, the only way to change it is to enter recovery mode:
Restart the computer, keep pressing the esc key, enter recovery mode, select root, press Enter, this will enter the root directory
The above is the detailed content of How to solve the problem of lack of permission after adding an account in Linux?. For more information, please follow other related articles on the PHP Chinese website!