Editing configuration files

classic Classic list List threaded Threaded
20 messages Options
Reply | Threaded
Open this post in threaded view
|

Editing configuration files

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

--
-- ACCU - Professionalism in programming - http://www.accu.org
-- My writing - https://sites.google.com/site/ianbruntlett/


--
ubuntu-users mailing list
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
Reply | Threaded
Open this post in threaded view
|

Re: Editing configuration files

Bret Busby-2
On 24/11/2018, Ian Bruntlett <[hidden email]> wrote:

> 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
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
Reply | Threaded
Open this post in threaded view
|

Re: Editing configuration files

Ian Bruntlett
Hi Bret,

On Fri, 23 Nov 2018 at 18:35, Bret Busby <[hidden email]> wrote:
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/


--
ubuntu-users mailing list
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
Reply | Threaded
Open this post in threaded view
|

Re: Editing configuration files

Colin Law
In reply to this post by Bret Busby-2


On Fri, 23 Nov 2018, 18:35 Bret Busby <[hidden email] wrote:
On 24/11/2018, Ian Bruntlett <[hidden email]> wrote:
> 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


--

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
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users

--
ubuntu-users mailing list
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
Reply | Threaded
Open this post in threaded view
|

Re: Editing configuration files

ubuntu-users mailing list
In reply to this post by Ian Bruntlett
On Fri, 23 Nov 2018 18:29:05 +0000, Ian Bruntlett wrote:
>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
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
Reply | Threaded
Open this post in threaded view
|

Re: Editing configuration files

Brian-277
On Fri 23 Nov 2018 at 19:48:30 +0100, Ralf Mardorf via ubuntu-users wrote:

> On Fri, 23 Nov 2018 18:29:05 +0000, Ian Bruntlett wrote:
> >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
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
Reply | Threaded
Open this post in threaded view
|

Re: Editing configuration files

ubuntu-users mailing list
On Fri, 23 Nov 2018 19:59:05 +0000, Brian wrote:
>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
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
Reply | Threaded
Open this post in threaded view
|

Re: Editing configuration files

Colin Law
On Fri, 23 Nov 2018 at 20:48, Ralf Mardorf via ubuntu-users
<[hidden email]> wrote:
> ...
> 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
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
Reply | Threaded
Open this post in threaded view
|

Re: Editing configuration files

Compdoc@hotrodpc.com
On 11/23/18 2:40 PM, Colin Law wrote:

> On Fri, 23 Nov 2018 at 20:48, Ralf Mardorf via ubuntu-users
> <[hidden email]> wrote:
>> ...
>> 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
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
Reply | Threaded
Open this post in threaded view
|

Re: Editing configuration files

Colin Law


On Fri, 23 Nov 2018, 23:51 compdoc <[hidden email] wrote:
On 11/23/18 2:40 PM, Colin Law wrote:

> On Fri, 23 Nov 2018 at 20:48, Ralf Mardorf via ubuntu-users
> <[hidden email]> wrote:
>> ...
>> 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




--
ubuntu-users mailing list
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users

--
ubuntu-users mailing list
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
Reply | Threaded
Open this post in threaded view
|

Re: Editing configuration files

ubuntu-users mailing list
On Sat, 24 Nov 2018 07:21:44 +0000, Colin Law wrote:
>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.

On Fri, 23 Nov 2018 21:40:37 +0000, Colin Law wrote:
>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
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
Reply | Threaded
Open this post in threaded view
|

Re: Editing configuration files

Colin Law
On Sat, 24 Nov 2018 at 08:39, Ralf Mardorf via ubuntu-users
<[hidden email]> wrote:

>
> On Sat, 24 Nov 2018 07:21:44 +0000, Colin Law wrote:
> >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
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
Reply | Threaded
Open this post in threaded view
|

Re: Editing configuration files

Colin Watson
In reply to this post by Ian Bruntlett
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                                       [[hidden email]]

--
ubuntu-users mailing list
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
Reply | Threaded
Open this post in threaded view
|

Re: Editing configuration files

Karl Auer
On Sat, 2018-11-24 at 12:38 +0000, Colin Watson wrote:
> 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 ([hidden email])
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
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
Reply | Threaded
Open this post in threaded view
|

Re: Editing configuration files

David Fletcher-5
In reply to this post by Ian Bruntlett
On Fri, 2018-11-23 at 18:29 +0000, Ian Bruntlett wrote:
> 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
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
Reply | Threaded
Open this post in threaded view
|

Re: Editing configuration files

Colin Watson
In reply to this post by Karl Auer
On Sun, Nov 25, 2018 at 12:04:50AM +1100, Karl Auer wrote:
> On Sat, 2018-11-24 at 12:38 +0000, Colin Watson wrote:
> > 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                                       [[hidden email]]

--
ubuntu-users mailing list
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
Reply | Threaded
Open this post in threaded view
|

Re: Editing configuration files

Liam Proven
In reply to this post by Ian Bruntlett
On Fri, 23 Nov 2018 at 19:31, Ian Bruntlett <[hidden email]> wrote:
>
> 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: [hidden email] - Google Mail/Hangouts/Plus: [hidden email]
Twitter/Facebook/Flickr: lproven - Skype/LinkedIn: liamproven
UK: +44 7939-087884 - ČR (+ WhatsApp/Telegram/Signal): +420 702 829 053

--
ubuntu-users mailing list
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
Reply | Threaded
Open this post in threaded view
|

Re: Editing configuration files

Kim Briggs
In reply to this post by Colin Law
On Fri, Nov 23, 2018 at 6:42 PM Colin Law <[hidden email]> wrote:


On Fri, 23 Nov 2018, 18:35 Bret Busby <[hidden email] wrote:
On 24/11/2018, Ian Bruntlett <[hidden email]> wrote:
> 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

I have been using "sudo gedit" for over a decade.  Don't tell the security people, but in my own home, I make the rules  :-)

--
ubuntu-users mailing list
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
Reply | Threaded
Open this post in threaded view
|

Re: Editing configuration files

Doug McGarrett

On 12/01/2018 05:24 PM, Kim Briggs wrote:
On Fri, Nov 23, 2018 at 6:42 PM Colin Law <[hidden email]> wrote:


On Fri, 23 Nov 2018, 18:35 Bret Busby <[hidden email] wrote:
On 24/11/2018, Ian Bruntlett <[hidden email]> wrote:
> 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

I have been using "sudo gedit" for over a decade.  Don't tell the security people, but in my own home, I make the rules  :-)

If you have a root-permissioned file browser, like Konqueror or Dolphin-root, you can activate Kate from inside it and edit a file with root permissions.

--doug




--
ubuntu-users mailing list
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
Reply | Threaded
Open this post in threaded view
|

Re: Editing configuration files

Andrew J. Caines-2
In reply to this post by Ian Bruntlett
Ian,
> What is the preferred way to edit text configuration files that require
> root access?

As others have mentioned, there are wrappers for some configs which
provide degrees of safety. My preferred method for making simple
substitution or addition changes with minimal foot-shooting opportunity
is with sed, e.g.

Show the line(s) to change

$ sed -n '/\/tmp/p' /etc/fstab
tmpfs /tmp tmpfs defaults,size=10% 0 0

Show how they will look after the change

$ sed -n '/\/tmp/s/10/25/p' /etc/fstab
tmpfs /tmp tmpfs defaults,size=25% 0 0

Make the change

$ sudo sed -i '/\/tmp/s/10/25/' /etc/fstab

See the new line(s)

$ sed -n '/\/tmp/p' /etc/fstab
tmpfs /tmp tmpfs defaults,size=25% 0 0

This also has the advantage of leaving no swap files, history, configs
or other unintended files owned by root. It also puts an explicit record
of the change conveniently in your shell history which may allow you to
easily revert the change, e.g.

$ sudo sed -i '/\/tmp/s/25/10/' /etc/fstab


--
-Andrew J. Caines-   Unix Systems Architect   [hidden email]
  "Machines take me by surprise with great frequency" - Alan Turing

--
ubuntu-users mailing list
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users