1

I had written a regular account name debian8 into sudoers file.

echo "debian8  ALL=(ALL:ALL) NOPASSWD:ALL" >> /etc/sudoers

To reboot and install some package.

sudo  dpkg -i Brackets*.deb
[sudo] password for debian8: 
Selecting previously unselected package brackets.
(Reading database ... 85361 files and directories currently installed.)

How to execute the command sudo dpkg -i Brackets*.deb directly ,without asking to input password?

Why is no use to set config as below?

sudo visudo -f /etc/sudoers.d/myRules
debian8   ALL=NOPASSWD: ALL

I fix the problem with following method.

sudo visudo -f /etc/sudoers
debian8   ALL=NOPASSWD: ALL

Why is no use to edit in /etc/sudoers.d/myRules?

2

Never, ever run things like echo something >> /etc/sudoers. One small typo, any kind of mistake, and you can break sudo on your system. You'll then have to boot into a live session, mount the local disk and undo what you broke. It's a pain to do and there are tools specifically esigned to help you avoid this sort of issue. So just always use sudo visudo. If you are not comfortable with the vim editor, you can use nano or any other editor instead by setting the EDITOR variable:

sudo EDITOR=/usr/bin/nano  visudo

Now, the first command you tried—the echo—although dangerous, should have worked. If it didn't, you probably ran something slightly different. Did you maybe run the command as debian8 and not as root?

If you run sudo visudo and add this line, it will work as expected:

debian8  ALL=(ALL:ALL) NOPASSWD:ALL

And no need for reboot, just close visudo. As for why adding your rule to /etc/sudoers.d/myRules failed, that's because you also need to tell sudoers to include any files in that directory. On my Arch system, the relevant section is commented out:

$ sudo grep 'sudoers\.d' /etc/sudoers
## Read drop-in files from /etc/sudoers.d
#includedir /etc/sudoers.d

So, to include rules set in /etc/sudoers.d, you need to run sudo visudo again and change (or insert) the above lines so they look like this:

## Read drop-in files from /etc/sudoers.d
includedir /etc/sudoers.d
  • Very, very important advice from you : "Never, ever run things like echo something >> /etc/sudoers." ! :) – cl-netbox Mar 18 '17 at 14:51
3

You should probably not be editing the /etc/sudoers file directly like that. Instead, either:

1.) use the command 'visudo' as root to edit the file
2.) even better, add you config changes as overrides in a separate file as follows:

sudo visudo -f /etc/sudoers.d/myRules

Now, enter the following line inside the text editor that opens:

debian8   ALL=NOPASSWD: ALL

Now, of course you can use Ctrl-O to write the file and then Ctrl-X to exit (if your visudo opens Nano, which mine does).

Hopefully this is helpful. Enjoy!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.