Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I've noticed that the sudoers file and cron config files act in a special way compared to other config files on Linux. They need to be edited with a special wrapper rather than any text editor. Why is this?

share|improve this question

2 Answers 2

up vote 60 down vote accepted

You use visudo mostly to prevent from breaking your system. Visudo runs checks on your changes to make sure you didn't mess anything up. If you did mess something up, you could completely wreck your ability to fix it or do anything requiring privileges without rebooting into a rescue mode.

The man page describes this.

visudo edits the sudoers file in a safe fashion, analogous to vipw(8). visudo locks the sudoers file against multiple simultaneous edits, provides basic sanity checks, and checks for parse errors. If the sudoers file is currently being edited you will receive a message to try again later.

share|improve this answer
1  
Interesting! +1, for illustrating a simple explanation for something that I should have known a long time ago :) –  Greg Meehan Jun 16 '09 at 1:58
3  
The behaviour of visudo is available generically as a command called sudoedit. This does the same lock/copy/edit/copy/unlock cycle (though obviously not with the parse step). One advantage this has is that it lets you give people sudo access to edit root-owned files without launching an editor as root, which might let them launch a shell from within the editor. If I shell out of my editor while running sudoedit, my euid is still my own. –  James F Jun 16 '09 at 7:38

Zoredache answer is perfect.

One more thing that can be worth to mention. You can use you favorite editor by setting

export EDITOR=whatevertexteditoryouwant

share|improve this answer
    
If you do that, it will still do the syntax-check step, or it will be equivalent of calling sudoedit like @James F suggested? –  Lohoris Dec 25 '11 at 11:57
    
Yes is the answer to your question. You can use almost any editor you can invoke from cli. –  cstamas Dec 25 '11 at 18:20
1  
It was not a yes or no question :V –  Lohoris Dec 25 '11 at 20:45
4  
It will do the syntax check. –  cstamas Dec 26 '11 at 8:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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