How to use visudo

If you don’t know what it is, you probably shouldn’t be using it. That said, to edit your /etc/sudoers file you need to use

sudo visudo

You have two “modes”
• Command mode – Press ‘ESC’ to access.
• Insert mode – Press ‘I’ to access.
You’re always in one or the other.

• To move the insertion point around, press ‘ESC’ and use the arrow keys.
• Once you’re where you want to be, press ‘I’ and start entering text.
• To delete a character, you need to be in command mode, select the character and press the delete key. (Note: not the Backspace key) You can do this in insert mode, but it does some funky things with the text.
• To save your changes, in command mode, type :w and press enter.
• To quit, in command mode, type :q and press enter.
• To quit without saving any changes, in command mode, type :q! and press enter.

Be careful, if you mess it up, you will no longer be able to sudo. Then you need to sudo to fix it. Bit of a problem there. To fix it, you need to login as root, run visudo, and fix the file.

Posted in Linux. 13 Comments »

13 Responses to “How to use visudo”

  1. mihai2k Says:

    Thank you for this post. Helped me a lot with my ubuntu🙂

  2. Keith Says:

    I spent an hour trying to figure out the V! editor; thanks so much for the post.

  3. Dan Says:

    Very clear and concise. Helped me. Thanks.

  4. Jared Says:

    This was helpful. Thanks for posting it. For some reason I couldn’t delete text correctly until I realized I had to type ‘d’ and then press the right arrow. Pressing ‘d’ then down would delete a whole line! ‘Vi’va la Emacs!

  5. deb Says:

    This was helpful — Thx

  6. Van Vo Says:

    This is wonderful documents. Good job! Mathew

  7. Muhammed Refaai Says:

    Reblogged this on Muhammed Refaai and commented:
    Interesting tip for adding your account on sudoers.d file!😉

  8. dtrain Says:

    Thanks for the help, you really saved me some time.
    Reblogged on dtraindesigns

  9. Vincenzo Says:

    Clear and concise explanation, thank you!!!!
    You saved me🙂

  10. Rayoomh Says:

    please I have a question but I can’t solve it, can you solve me. I must to do it in LUNIX.


    – enter the command (visudo) t edit the /etc/sudoers file. what is the command Alias for /usr/bin/updated?

  11. dowlers Says:

    My sudo is messed up but I could run visudo using: pkexec visudo

    • Athaariq Ardiansyah Says:

      if you’re using mac os x, you’re lucky

      first, if you are using El Capitan, disable System Integration Protection (how to: )

      and then, go to /etc by pressing Shift+Command+G on desktop then type: /etc

      you will find “sudoers” and “sudoers~orig”, that’s it! delete “sudoers” file then rename “sudoers~orig” to be “sudoers” (if you’re not allowed to rename, makesure you’re using your main account then change Everyone to Read and Write on Get Info)

      REMEMBER!! this is your last chance to rescue sudo. if you messed up your sudo again, there’s no way except clean instal mac os x :.(

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: