In /etc/sudoers, it says:

# This file MUST be edited with the 'visudo' command as root.

My question is, why must this file be edited with visudo?

It seems I was able to edit the file successfully with gedit, by issuing: sudo gedit /etc/sudoers.

If I was able to edit it with gedit, why must I use visudo?


It is just safer to use visudo. You can edit /etc/sudoers directly, but if you make a typo there, you will not be able to use sudo anymore. And won't be able to fix your error.

visudo locks the sudoers file against multiple simultaneous edits, provides basic sanity checks, and checks for parse errors.

You can read more by:

man visudo
  • Why is it safer? What does visudo do to make it safer? – Tosh May 19 '15 at 20:14
  • I added to the answer. – Pilot6 May 19 '15 at 20:15
  • Thanks! An off-topic question if you don't mind: what is the difference between # and % in the sudoers file? Are they both there to indicate the line is a comment? – Tosh May 19 '15 at 20:17
  • 4
    Only # is a comment. % is for group. And if you do not know file format, you definitely should not directly edit sudoers. – Pilot6 May 19 '15 at 20:19
  • Thanks again. I have to do it following the instructions here winscp.net/eng/docs/faq_su. – Tosh May 19 '15 at 20:21

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.