Discussion:
Editing configuration files
Ian Bruntlett
2018-11-23 18:29:05 UTC
Permalink
Hi All,

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

TIA,


Ian
--
-- ACCU - Professionalism in programming - http://www.accu.org
-- My writing - https://sites.google.com/site/ianbruntlett/
-- Free Software page -
https://sites.google.com/site/ianbruntlett/home/free-software
Bret Busby
2018-11-23 18:34:33 UTC
Permalink
Post by Ian Bruntlett
Hi All,
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
TIA,
Ian
Have you tried
sudo vi <filename>
?
--
Bret Busby
Armadale
West Australia

..............

"So once you do know what the question actually is,
you'll know what the answer means."
- Deep Thought,
Chapter 28 of Book 1 of
"The Hitchhiker's Guide to the Galaxy:
A Trilogy In Four Parts",
written by Douglas Adams,
published by Pan Books, 1992

....................................................
--
ubuntu-users mailing list
ubuntu-***@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubu
Ian Bruntlett
2018-11-23 18:39:38 UTC
Permalink
Hi Bret,
Post by Bret Busby
Have you tried
sudo vi <filename>
On occasion. I don't typically use vi much. Usually as a means of last
resort :)


Ian
--
-- ACCU - Professionalism in programming - http://www.accu.org
-- My writing - https://sites.google.com/site/ianbruntlett/
-- Free Software page -
https://sites.google.com/site/ianbruntlett/home/free-software
Colin Law
2018-11-23 18:41:10 UTC
Permalink
Post by Bret Busby
Post by Ian Bruntlett
Hi All,
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
TIA,
Ian
Have you tried
sudo vi <filename>
?
Or nano. It would be nice if there were a GUI editor that could edit root
owned files.

Colin
Post by Bret Busby
--
Bret Busby
Armadale
West Australia
..............
"So once you do know what the question actually is,
you'll know what the answer means."
- Deep Thought,
Chapter 28 of Book 1 of
A Trilogy In Four Parts",
written by Douglas Adams,
published by Pan Books, 1992
....................................................
--
ubuntu-users mailing list
https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
Ralf Mardorf via ubuntu-users
2018-11-23 18:48:30 UTC
Permalink
Post by Ian Bruntlett
What is the preferred way to edit text configuration files that require
root access?
Hi,

it depends on the config file you want to edit. If you want to edit
/etc/sudoers you should use visudo, since it locks the file and checks
the file's syntax. The "vi" in visudo doesn't mean that you must use
"vi", you could use the another editor, since by default it cares about
the VISUAL and EDITOR variables. I'm using nano, for visudo, but
sometimes I'm even using dconf based GUI editors for some config
files, which could lead to /run/user/*/dconf/user owner issues, that
could be resolved by simply deleting /run/user/*/dconf/user after
usage. OTOH some GUI editors aren't that odd, for example xfw could be
used and doesn't cause such an owner issue. I sometimes like to use meld
to edit files and to compare it with backups or "new" files installed
by an upgrade, while the old file is kept.

2 Cents,
Ralf
--
ubuntu-users mailing list
ubuntu-***@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubunt
Brian
2018-11-23 19:59:05 UTC
Permalink
Post by Ralf Mardorf via ubuntu-users
Post by Ian Bruntlett
What is the preferred way to edit text configuration files that require
root access?
Hi,
it depends on the config file you want to edit. If you want to edit
/etc/sudoers you should use visudo, since it locks the file and checks
the file's syntax. The "vi" in visudo doesn't mean that you must use
"vi", you could use the another editor, since by default it cares about
the VISUAL and EDITOR variables. I'm using nano, for visudo, but
sometimes I'm even using dconf based GUI editors for some config
files, which could lead to /run/user/*/dconf/user owner issues, that
could be resolved by simply deleting /run/user/*/dconf/user after
usage. OTOH some GUI editors aren't that odd, for example xfw could be
used and doesn't cause such an owner issue. I sometimes like to use meld
to edit files and to compare it with backups or "new" files installed
by an upgrade, while the old file is kept.
The comment on visudo is very perceptive, informative and useful. The
same comment applies to vigr and vipw. For editing /etc/default/grub
any editor is good enough.
--
Brian.
--
ubuntu-users mailing list
ubuntu-***@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mail
Ralf Mardorf via ubuntu-users
2018-11-23 20:46:11 UTC
Permalink
For editing [snip] any editor is good enough.
Yesno, I like nano not only because it's easy to use, but also because
you could use it with an easy to edit nanorc file, for highlighting the
content of even your private obscure foo-bar.config.txt file, without
studying rocket science. I seriously doubt that any idiot with an
alcohol intoxication is able to use either emacs, nor vi{,m}.
Configuring and using nano could be done by anybody under nearly any
altered state of consciousness. So why not using it, even if we
should prefer to live Straight Edge and/or rocket science should be our
daily bread?
--
ubuntu-users mailing list
ubuntu-***@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubu
Colin Law
2018-11-23 21:40:37 UTC
Permalink
On Fri, 23 Nov 2018 at 20:48, Ralf Mardorf via ubuntu-users
Post by Ralf Mardorf via ubuntu-users
...
Configuring and using nano could be done by anybody under nearly any
altered state of consciousness. So why not using it, even if we
should prefer to live Straight Edge and/or rocket science should be our
daily bread?
nano is ok for small files but is pretty tedious for large config
files. Compared to even a simple gui editor like gedit, stuff like
search and replace for example is not simple unless you use nano all
the time, which most of us don't.

Colin
--
ubuntu-users mailing list
ubuntu-***@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists
compdoc
2018-11-23 23:50:03 UTC
Permalink
Post by Colin Law
On Fri, 23 Nov 2018 at 20:48, Ralf Mardorf via ubuntu-users
Post by Ralf Mardorf via ubuntu-users
...
Configuring and using nano could be done by anybody under nearly any
altered state of consciousness. So why not using it, even if we
should prefer to live Straight Edge and/or rocket science should be our
daily bread?
nano is ok for small files but is pretty tedious for large config
files. Compared to even a simple gui editor like gedit, stuff like
search and replace for example is not simple unless you use nano all
the time, which most of us don't.
Colin
I run nautilus/caja with sudo, then browse to the .conf file location,
double-click it and gedit opens as superuser.

Is that not suggested? Its worked for me for a long time.
--
ubuntu-users mailing list
ubuntu-***@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listi
Colin Law
2018-11-24 07:21:44 UTC
Permalink
Post by compdoc
Post by Colin Law
On Fri, 23 Nov 2018 at 20:48, Ralf Mardorf via ubuntu-users
Post by Ralf Mardorf via ubuntu-users
...
Configuring and using nano could be done by anybody under nearly any
altered state of consciousness. So why not using it, even if we
should prefer to live Straight Edge and/or rocket science should be our
daily bread?
nano is ok for small files but is pretty tedious for large config
files. Compared to even a simple gui editor like gedit, stuff like
search and replace for example is not simple unless you use nano all
the time, which most of us don't.
Colin
I run nautilus/caja with sudo, then browse to the .conf file location,
double-click it and gedit opens as superuser.
Is that not suggested? Its worked for me for a long time.
Which version of Ubuntu are you doing that with? Often running a graphic
app with sudo will leave root-owned files on your home folder which then
causes problems.

Colin
Post by compdoc
--
ubuntu-users mailing list
https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
Ralf Mardorf via ubuntu-users
2018-11-24 08:37:17 UTC
Permalink
Which version of Ubuntu are you doing that with?  Often running a
graphic app with sudo will leave root-owned files on your home folder
which then causes problems.
In my experience _only_ dconf based editors _sometimes_ (not always)
change the owner of /run/user/*/dconf/user,
e.g. /run/user/1000/dconf/user, but files in $HOME aren't affected.
nano is ok for small files but is pretty tedious for large config
files. Compared to even a simple gui editor like gedit, stuff like
search and replace for example is not simple unless you use nano all
the time, which most of us don't.
I'll agree to that.

The Ubuntu package xfe contains /usr/bin/xfwrite, for some, at
least one other distros it's /usr/bin/xfw. It's a GUI editor with a
search and replace option, that doesn't use dconf, so
/run/user/*/dconf/user isn't touched at all and in my experiences
$HOME isn't affected either.

However, even if a config file (perhaps .config/xfe/xfwrc) related to
xfwrite (xfw) in $HOME should be affected, simply make it your root
privileges GUI editor and don't use it as user. Other than dconf, the
xfwrite (xfw) config has got no impact on other apps.
--
ubuntu-users mailing list
ubuntu-***@lists.ubuntu.com
Modify settings or unsubscribe at: https://l
Colin Law
2018-11-24 08:48:44 UTC
Permalink
On Sat, 24 Nov 2018 at 08:39, Ralf Mardorf via ubuntu-users
Post by Ralf Mardorf via ubuntu-users
Post by Colin Law
Which version of Ubuntu are you doing that with? Often running a
graphic app with sudo will leave root-owned files on your home folder
which then causes problems.
In my experience _only_ dconf based editors _sometimes_ (not always)
change the owner of /run/user/*/dconf/user,
e.g. /run/user/1000/dconf/user, but files in $HOME aren't affected.
I thought the bigger problem was with .Xauthority.

Colin
--
ubuntu-users mailing list
ubuntu-***@lists.ubuntu.com
Modify settings or unsubscribe at: https://l
Colin Watson
2018-11-24 12:38:24 UTC
Permalink
Post by Ian Bruntlett
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 [***@ubuntu.com]
--
ubuntu-users mailing list
ubuntu-***@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.c
Karl Auer
2018-11-24 13:04:50 UTC
Permalink
Post by Colin Watson
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 are preferred recommended way to edit some files. For example,
editing crontab should be done with "crontab -e", editing /etc/passwd
should be done with vipw, editing /etc/groups should be done with vigr,
editing the sudoers file should be done with visudo. The common
property these techniques share is that they put a lock on the file
that is respected by other programs that may also modify these files,
e.g. passwd; the lock makes sure that changes are applied in the right
order and not overwritten.

Especially for single-user systems - these aren't that important.

Regards, K.
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Karl Auer (***@biplane.com.au)
http://www.biplane.com.au/kauer
http://twitter.com/kauer389

GPG fingerprint: A0CD 28F0 10BE FC21 C57C 67C1 19A6 83A4 9B0B 1D75
Old fingerprint: A52E F6B9 708B 51C4 85E6 1634 0571 ADF9 3C1C 6A3A
--
ubuntu-users mailing list
ubuntu-***@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listin
Colin Watson
2018-11-24 13:31:34 UTC
Permalink
Post by Karl Auer
Post by Colin Watson
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 are preferred recommended way to edit some files.
I understand why you responded to me in this way, and of course you're
quite right about those specific cases. I misphrased the last part of
the sentence above; what I intended to say was "a single preferred way
to edit files in general".
--
Colin Watson [***@ubuntu.com]
--
ubuntu-users mailing list
ubuntu-***@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listin
David Fletcher
2018-11-24 13:15:46 UTC
Permalink
Post by Ian Bruntlett
Hi All,
What is the preferred way to edit text configuration files that
require root access?
Nobody has mentioned using joe, for example
sudo joe /etc/aliases

joe has a default line length limit which I've not managed to
permanently override by a config file but for editing files with longer
line lengths, for example
sudo joe -rmargin 200 /etc/postfix/header_checks_regexp

does the trick. I only need to do a reverse command search for the file
name I regularly edit. Easy.

Ctrl-K H
puts up the help display.

Just another editing option, which I happen to prefer.

Dave
--
ubuntu-users mailing list
ubuntu-***@lists.ubuntu.com
Modify settings or unsubscribe at: htt
Liam Proven
2018-11-25 20:07:43 UTC
Permalink
Post by Ian Bruntlett
Hi All,
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
Er. Depends on display server -- Wayland makes it more complicated --
but you can use your GUI editor of choice.

Open a terminal.
Do ``sudo -s'' to become root.
Navigate to the file, e.g. ``cd /etc/apt''
Open the editor, e.g. ``gedit sources.list''

That's what I do.

If apps running as root don't have permission to access the graphics
display, which I think is the default on Ubuntu but isn't on (e.g.)
openSUSE, you can add it with ``xhost+''

https://wiki.archlinux.org/index.php/Xhost

If you want a nice friendly GUI-like editor for the console, my
favourite is Tilde:

https://os.ghalkes.nl/tilde/
--
Liam Proven - Profile: https://about.me/liamproven
Email: ***@cix.co.uk - Google Mail/Hangouts/Plus: ***@gmail.com
Twitter/Facebook/Flickr: lproven - Skype/LinkedIn: liamproven
UK: +44 7939-087884 - ČR (+ WhatsApp/Telegram/Signal): +420 702 829 053
--
ubuntu-users mailing list
ubuntu-***@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listin
Loading...