sudoedit - a Safer Alternative
Suggestion
Use sudoedit instead of sudo {insert-gui-editor-here}
Why?
Running many GUI programs as root can cause settings to be saved under YOUR HOME (/home/userid), not root’s HOME (/root/). This can be a huge problem.
If it is the first time a specific program is run, it can create the file with root as the owner, so running that same program later without sudo will see preferences not be saved. Some programs will refuse to run at all. Some will just crash.
A few weeks ago helping a completely new Linux user who happened to run sudo gedit before running any other program on his fresh install. ~/.gnome2/ was created and owned by root. That prevented any other gnome2-based program from creating any settings – a few just crashed – from the GUI, it was silent. Click, wait, wait, wait – nothing.
sudoedit works like visudo -
- it copies the file to be edited to a temporary location,
- runs the $EDITOR as the normal userid,
- when done, copies the file back to the protected location.
The EDITOR environment variable can be set to whatever the user likes best – nano, vim, gedit, geany, even, cough, cough, emacs or something else. ;) By default, nano is set on many distros. A reasonable default, I suppose.
Many people might prefer to use gedit under a GUI, but nano on a server. The EDITOR variable is setup once and the command, sudoedit, remains the same for the same purpose.
Why Not?
Of course, if you use a text-based editor with sudo already, the risks are minimal. Also, if you remember to use gksudo when running a GUI, great. I don’t.
However, when coaching newbies, please remember they can easily get into trouble before understanding multi-user concepts. sudoedit solves that problem.
Want to Know More?
What’s So Great About Sudoedit? has a nice intro from a different perspective.