Ubuntu recovery after sudoers is changed

Source: Internet
Author: User

Sudo is the most widely used Ubuntu System (compared with other popular Linux systems ), whether a common user has the sudo permission to temporarily switch to the root user to execute the "One Line" command depends on the configuration of/etc/sudoers, sudoers, however, cannot be modified in the conventional way.

The common method is to use chmod to grant write permissions to users who can manipulate the file. After modifying the file, you can restore the permission. However, the default permission for sudoers is 440 of root:

-r--r----- 1 root root 4002 Mar  2  2012 /etc/sudoers

Once the permission is changed to a value other than 440, The sudo command cannot be used. For other Linux systems, the root user of Ubuntu is disabled by default. The root user cannot use it, and The sudo command cannot be used. If it is better to say other files, the permissions of this file will be almost a little too large.

At this time, you can only go to the single-user mode for repair. Ubuntu enters the single-user mode by restarting and selecting the recovery mode option. (If multiple systems exist, the GRUB menu is displayed, select the recovery mode option to enter. If there is only one Ubuntu system, press shift to display the GRUB menu ), after loading for a short time, you can select the repair option. In this case, select the root option, which is the way to enter in single-user root mode.

Use chmod to change the sudoers file permission back to 440. Previously, sudo users can use the sudo file normally:

 chmod 440 /etc/sudoers

If the read-only file system prompt does not allow modification, you can re-mount the file to solve the problem:

mount -o remount rw / 

In this case, passwd can also be used to set the password for the root user. In the future, such a Oolong will not need to be restarted into the single-user mode. However, it is still not recommended that you open the root user. I think it is reasonable to disable the root user to limit the influence scope of the command.

Log on to the system. The correct method to modify the sudoers file has already been uninstalled, that is, to use the mongodo command to modify this special file.

## This file must be edited with the ‘visudo‘ command.

Use a user with sudo permission to execute:

sudo visudo

In the root all = (all) All line, write a line to learn the format of this line, add the user who needs to use the sudo command to it, and overwrite the source file when saving it.

root ALL=(ALL) ALLuser ALL=(ALL) ALL

Okay. Solve the problem.

I hope you will take the lessons you have taken as a warning. If you find this article, you can quickly solve the problem. At the same time, I will remind myself.

Ubuntu recovery after sudoers is changed

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.