How to execute sudo command without entering a password under Linux

Source: Internet
Author: User

As a desktop system such as Ubuntu, the default login account does not have root permissions, in order to enhance the permissions to perform tasks, we generally use the sudo+ command to execute, but it is not difficult to find that we generally have to enter the password. So is there any way we can execute sudo without entering a password? Of course it is. That is to modify the sudoers file.

How do I modify sudoers? Directly modify/etc/sudoers? No, that kind of modification can easily cause a privilege disorder. When the cows are manually modified, because they are not so understanding of the format, so the editor of the error many times, so do not recommend the direct modification method. We can use Visudo to edit.

Go to the terminal, execute sudo visudo

Some rules are listed below #user Privilege specification, and what we need to do now is to do something about our users. If our user name is Nenew

On the last line of the file, add:

Nenew all= (All) Nopasswd:all

Then save exit, execute

sudo usermod-ag admin nenew

Reboot to see nenew account execution sudo still need a password? Here we need to understand the sequence of this issue, on the Ubuntu wiki has a more detailed description.

%admin all= (All)
This line only makes the Admin group users have the ability to execute commands like any account, but still need a password, so we need to add our nenew users to the admin group, so there's sudo usermod-ag admin nenew, It is then nopasswd defined, and this line must be followed by the%admin all= (all).

After the article is playing a lot of friends put forward unsafe problems, indeed, this is a security risk. The purpose of this article is also to let you understand the order of the sudoers, of course, we can put the final

Nenew all= (All) Nopasswd:all changed to restrict the command, such as canceling a password for a shutdown command

Nenew all= (All) Nopassws:/sbin/shutdown,/sbin/halt,/sbin/reboot

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.