-1

I want to be able to run visudo without sudo (because visudo obviously wants to be used as root), but I want it to prompt for my password (for security reason). Is there any way to do this? Something opposite of NOPASSWD.

  • 2
    alias visudo='sudo visudo' – Mark Plotnick Aug 15 '18 at 22:46
1

You can't have it both ways.

Only root has the ability to edit the sudoers file which is what visudo does. The default permissions for the sudoers file are 440 which is why visudo is used to edit it and only root can use that command.

The sudo command will refuse to work if the permissions for the sudoers file are not 440 in order to avoid ruining the system.

It's not worth the trouble just so you can attempt to avoid typing sudo because it will just break your system and not work anyway. The security that you are looking for is already in place.

  • visudo does more than that, it locks the sudoers file while you're editing it and it also syntax checks the edits before allowing you to commit them. – slm Aug 15 '18 at 23:35
  • @slm Yes, it does, which is why it should always be used instead of using a text editor on the sudoers file itself. In this case, I was only trying to explain why it's not a good idea to mess with that file just for the purpose of not having to use sudo when using the visudo command. – Nasir Riley Aug 16 '18 at 0:09
  • Just expanding, not being critical 8-) – slm Aug 16 '18 at 0:16
  • I have seen docker and systemctl doing it this way, so I thought that there is a general solution. – Franklin Yu Aug 16 '18 at 0:17
  • 1
    @FranklinYu The docker group has rights to run the docker commands. The sudoers file can only be accessed and edited by root which includes doing it via the visudo command. – Nasir Riley Aug 16 '18 at 16:36

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.