Editing configuration files

Colin Watson cjwatson at ubuntu.com
Sat Nov 24 12:38:24 UTC 2018

On Fri, Nov 23, 2018 at 06:29:05PM +0000, Ian Bruntlett wrote:
> What is the preferred way to edit text configuration files that require
> root access?
> For example, I would normally use emacs to edit /etc/default/grub

I don't think it can realistically be said that there is a single
preferred way to do this, any more than there's a single preferred way
to edit any file.

There's definitely something to be said for using your normal editor in
combination with some way for the editor to elevate privileges
internally in order to read/write individual files (as opposed to
running the entire editor with root privileges); it does involve some
plumbing, and isn't possible with all editors, but people generally make
fewer mistakes when their editing environment is a familiar one.

My own preference (and I'm not pretending that this is something I'd
recommend to everyone, but that's no reason not to share it for those it
might help since there are plenty of vim users out there) is to use the
:SudoWrite or :SudoEdit commands from
https://github.com/tpope/vim-eunuch with vim.  I think you can do
similar things in a more general way with emacs' TRAMP package.

Colin Watson                                       [cjwatson at ubuntu.com]

More information about the ubuntu-users mailing list