* Re: I'am root user, but 'emacs /etc/sudoers' still report Buffer is read-only: #<buffer sudoers> in modeline
2015-04-29 6:27 I'am root user, but 'emacs /etc/sudoers' still report Buffer is read-only: #<buffer sudoers> in modeline Show Dont
@ 2015-04-29 8:25 ` Bob Proulx
2015-04-29 8:36 ` tomas
` (3 subsequent siblings)
4 siblings, 0 replies; 10+ messages in thread
From: Bob Proulx @ 2015-04-29 8:25 UTC (permalink / raw)
To: Show Dont; +Cc: help-gnu-emacs
Show Dont wrote:
> I want to edit /etc/sudoers for add 'git ALL=(ALL:ALL) ALL' in it. I
> am ready the root user, but emacs still can not edit the
> /etc/sudoers.
Use C-q C-x to toggle read-only status. It starts off read-only
because the file permissions are read-only. If you are the root
superuser then you can toggle the buffer read-only status and then
edit the file anyway and override the file permissions on save and
write the file anyway.
Here is the documentation.
https://www.gnu.org/software/emacs/manual/html_node/emacs/Misc-Buffer.html
Specifically for the suders file it is a good idea to use the
'visudo' command to edit that file. It will make a copy of the file
for editing and then will validate the syntax before saving. It
prevents typos and accidents breaking the sudo configuration, which
might prevent a sudo only user from having sudo to fix the problem.
'visudo' respects the EDITOR variable and will invoke emacs as the
editor if EDITOR is set to emacs.
I highly recommend using the visudo command for editing the
/etc/sudoers file. It will make a writable copy and therefore you
won't need to toggle the read-only status.
Bob
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: I'am root user, but 'emacs /etc/sudoers' still report Buffer is read-only: #<buffer sudoers> in modeline
2015-04-29 6:27 I'am root user, but 'emacs /etc/sudoers' still report Buffer is read-only: #<buffer sudoers> in modeline Show Dont
2015-04-29 8:25 ` Bob Proulx
@ 2015-04-29 8:36 ` tomas
2015-04-29 9:24 ` Alex Kost
` (2 subsequent siblings)
4 siblings, 0 replies; 10+ messages in thread
From: tomas @ 2015-04-29 8:36 UTC (permalink / raw)
To: Show Dont; +Cc: help-gnu-emacs
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Tue, Apr 28, 2015 at 11:27:36PM -0700, Show Dont wrote:
> I want to edit /etc/sudoers for add 'git ALL=(ALL:ALL) ALL' in it. I am ready the root user, but emacs still can not edit the /etc/sudoers.
What happens exactly?
- -- t
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)
iEYEARECAAYFAlVAmBMACgkQBcgs9XrR2kYrZQCfQZyz0+rT96CVDqj+2i0zS7I9
6J8AnjPfnkRfcVdzs7lYeaANGwyexz0V
=xVxH
-----END PGP SIGNATURE-----
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: I'am root user, but 'emacs /etc/sudoers' still report Buffer is read-only: #<buffer sudoers> in modeline
2015-04-29 6:27 I'am root user, but 'emacs /etc/sudoers' still report Buffer is read-only: #<buffer sudoers> in modeline Show Dont
2015-04-29 8:25 ` Bob Proulx
2015-04-29 8:36 ` tomas
@ 2015-04-29 9:24 ` Alex Kost
2015-04-29 10:33 ` tomas
[not found] ` <mailman.1889.1430298251.904.help-gnu-emacs@gnu.org>
4 siblings, 0 replies; 10+ messages in thread
From: Alex Kost @ 2015-04-29 9:24 UTC (permalink / raw)
To: Show Dont; +Cc: help-gnu-emacs
Show Dont (2015-04-29 09:27 +0300) wrote:
> I want to edit /etc/sudoers for add 'git ALL=(ALL:ALL) ALL' in it. I am ready the root user, but emacs still can not edit the /etc/sudoers.
Usually "/etc/sudoers" is not writable (permission is 440) and is
intended to be edited using "visudo" command.
--
Alex
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: I'am root user, but 'emacs /etc/sudoers' still report Buffer is read-only: #<buffer sudoers> in modeline
2015-04-29 6:27 I'am root user, but 'emacs /etc/sudoers' still report Buffer is read-only: #<buffer sudoers> in modeline Show Dont
` (2 preceding siblings ...)
2015-04-29 9:24 ` Alex Kost
@ 2015-04-29 10:33 ` tomas
[not found] ` <mailman.1889.1430298251.904.help-gnu-emacs@gnu.org>
4 siblings, 0 replies; 10+ messages in thread
From: tomas @ 2015-04-29 10:33 UTC (permalink / raw)
To: Show Dont; +Cc: help-gnu-emacs
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Tue, Apr 28, 2015 at 11:27:36PM -0700, Show Dont wrote:
> I want to edit /etc/sudoers for add 'git ALL=(ALL:ALL) ALL' in it. I am ready the root user, but emacs still can not edit the /etc/sudoers.
Note: as Bob and Alex already pointed out, visudo is the right way
to do that. Not only it manages the read-only thingie, but it does
sanity checks on the sudoers file: if you've managed to shut yourself
out of root because of a silly typo in the sudoers file, you'll learn
to appreciate that feature :-)
- -- t
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)
iEYEARECAAYFAlVAs5cACgkQBcgs9XrR2kbHEACdE+38FbapZ+KRn2I+qPkDg6pP
23UAnA79eRmqzoeiHTQ/5LyiYrci97E5
=/d4X
-----END PGP SIGNATURE-----
^ permalink raw reply [flat|nested] 10+ messages in thread
[parent not found: <mailman.1889.1430298251.904.help-gnu-emacs@gnu.org>]
* Re: I'am root user, but 'emacs /etc/sudoers' still report Buffer is read-only: #<buffer sudoers> in modeline
[not found] ` <mailman.1889.1430298251.904.help-gnu-emacs@gnu.org>
@ 2015-04-29 20:08 ` Emanuel Berg
2015-04-29 20:29 ` Emanuel Berg
0 siblings, 1 reply; 10+ messages in thread
From: Emanuel Berg @ 2015-04-29 20:08 UTC (permalink / raw)
To: help-gnu-emacs
Bob Proulx <bob@proulx.com> writes:
> I highly recommend using the visudo command for
> editing the /etc/sudoers file. It will make
> a writable copy and therefore you won't need to
> toggle the read-only status.
Indeed, however because you must run Emacs with
superuser rights in order to edit /etc/sudoers (i.e.
you won't get your everyday user's Emacs configs) it
can be preferable to use something altogether
different and above all more simple, like nano, which
seems to be the default - in spite of the name (or
perhaps "vi"sudo refers to "visual" and not vi(m)).
If you are dead set on using Emacs, try
sudo EDITOR='/usr/bin/emacs -u USER' visudo
However then be aware that all tildes (~) in USER's
configs won't be /home/USER, so those have to be
changed to explicit paths unless there is yet another
way around it.
Perhaps the `user-login-name' or
`user-real-login-name' could be experimented with...
--
underground experts united
http://user.it.uu.se/~embe8573
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: I'am root user, but 'emacs /etc/sudoers' still report Buffer is read-only: #<buffer sudoers> in modeline
2015-04-29 20:08 ` Emanuel Berg
@ 2015-04-29 20:29 ` Emanuel Berg
2015-04-30 21:36 ` Bob Proulx
[not found] ` <mailman.2062.1430429791.904.help-gnu-emacs@gnu.org>
0 siblings, 2 replies; 10+ messages in thread
From: Emanuel Berg @ 2015-04-29 20:29 UTC (permalink / raw)
To: help-gnu-emacs
Emanuel Berg <embe8573@student.uu.se> writes:
> However then be aware that all tildes (~) in USER's
> configs won't be /home/USER, so those have to be
> changed to explicit paths unless there is yet
> another way around it.
>
> Perhaps the `user-login-name' or
> `user-real-login-name' could be experimented with...
Yes. I just came up with it but it makes sense (I
think).
For /etc/sudoers use:
sudo LOGNAME=USER EDITOR='/usr/bin/emacs' visudo
Note that -u USER is isn't necessary with LOGNAME.
Tildes (~) in config files have to be replaced with
(user-login-name), e.g.:
(setq load-path
(append load-path
`(,(format "/home/%s/.emacs.d/emacs-init/" (user-login-name))
,(format "/home/%s/.emacs.d/emacs-init/w3m/" (user-login-name))
,(format "/home/%s/.emacs.d/emacs-init/gnus/" (user-login-name))
)))
`user-login-name' will report the (correct) user even
without the LOGNAME set (however not in sudo
invocation, which is why LOGNAME *is* set there) so it
will work transparently, is the thought.
--
underground experts united
http://user.it.uu.se/~embe8573
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: I'am root user, but 'emacs /etc/sudoers' still report Buffer is read-only: #<buffer sudoers> in modeline
2015-04-29 20:29 ` Emanuel Berg
@ 2015-04-30 21:36 ` Bob Proulx
[not found] ` <mailman.2062.1430429791.904.help-gnu-emacs@gnu.org>
1 sibling, 0 replies; 10+ messages in thread
From: Bob Proulx @ 2015-04-30 21:36 UTC (permalink / raw)
To: help-gnu-emacs
Emanuel Berg wrote:
> Indeed, however because you must run Emacs with
> superuser rights in order to edit /etc/sudoers (I.e.
> you won't get your everyday user's Emacs configs)
That depends upon how you invoked sudo and emacs. Normally you will
have your non-root emacs configuration.
$ sudo printenv HOME USER
/home/rwp
root
When running commands such as 'sudo emacs' the process id is changed,
and USER=root, but the HOME variable is not changed. However that is
configurable. It is possible your system has been configured
otherwise. But that would be the normal default for most people.
> it can be preferable to use something altogether
> different and above all more simple, like nano, which
> seems to be the default -
Because both emacs and vim (the two most popular technical editors)
need some knowledge and learning in order to use them distributions
often include nano as a simple editor that can be used without any
pre-existing knowledge. Nano includes an on screen menu so that you
need learn nothing ahead of the time of using it. And there are few
features beyond what is available on the menu.
> in spite of the name (or perhaps "vi"sudo refers to "visual" and not
> vi(m)).
It really meant vi. The 'visudo' name follows 'vipw' program (and
'vigr') which originally would spawn vi on the password file. Or any
other program as specified in the EDITOR field. But they fell back to
using vi if EDITOR was not set. Now in the modern age things are more
configurable for different user preferences such as editor.
It was long very popular to use use the language "vi a file" as a
generic in the same way that people might say Kleenex or Escalator or
Xerox even though those are all company tradmarks and should not be
used generically.
And so we have vipw and visudo which both would have originally
spawned vi on the respective files. But now the vi part of the name
of those classic tools is used generically to mean edit the file.
Anything else would require changing the name and that would be
egregiously breaking scripts and things that used the previous name.
> If you are dead set on using Emacs, try
>
> sudo EDITOR='/usr/bin/emacs -u USER' visudo
Not necessary when using the typical sudo configuration. Really! :-)
What does this say for you?
$ sudo printenv HOME
Bob
^ permalink raw reply [flat|nested] 10+ messages in thread
[parent not found: <mailman.2062.1430429791.904.help-gnu-emacs@gnu.org>]
* Re: I'am root user, but 'emacs /etc/sudoers' still report Buffer is read-only: #<buffer sudoers> in modeline
[not found] ` <mailman.2062.1430429791.904.help-gnu-emacs@gnu.org>
@ 2015-05-01 1:23 ` Emanuel Berg
2015-05-01 2:31 ` Emanuel Berg
1 sibling, 0 replies; 10+ messages in thread
From: Emanuel Berg @ 2015-05-01 1:23 UTC (permalink / raw)
To: help-gnu-emacs
Bob Proulx <bob@proulx.com> writes:
> And so we have vipw and visudo which both would have
> originally spawned vi on the respective files.
> But now the vi part of the name of those classic
> tools is used generically to mean edit the file.
> Anything else would require changing the name and
> that would be egregiously breaking scripts and
> things that used the previous name.
No, hands off "visudo"! :)
>> If you are dead set on using Emacs, try
>>
>> sudo EDITOR='/usr/bin/emacs -u USER' visudo
>
> Not necessary when using the typical sudo
> configuration. Really! :-) What does this say
> for you?
>
> $ sudo printenv HOME
Indeed:
/root
Nice catch! I wonder how that happened. Probably my
hacker friends in the FSB. Investigating...
--
underground experts united
http://user.it.uu.se/~embe8573
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: I'am root user, but 'emacs /etc/sudoers' still report Buffer is read-only: #<buffer sudoers> in modeline
[not found] ` <mailman.2062.1430429791.904.help-gnu-emacs@gnu.org>
2015-05-01 1:23 ` Emanuel Berg
@ 2015-05-01 2:31 ` Emanuel Berg
1 sibling, 0 replies; 10+ messages in thread
From: Emanuel Berg @ 2015-05-01 2:31 UTC (permalink / raw)
To: help-gnu-emacs
Bob Proulx <bob@proulx.com> writes:
> Not necessary when using the typical sudo
> configuration.
OK, this line in /etc/sudoers does it:
Defaults env_keep += "HOME LOGNAME EDITOR"
Then one can just do 'sudo visudo' and the tildes (the
~s) in the configs can be left tildes and still refer
to HOME.
LOGNAME is preserved otherwise this line
(setq inhibit-startup-echo-area-message "incal")
will break.
EDITOR is to get Emacs, of course.
I don't know if this is something that people
"typically" bother with, but now it works, and some
knowledge has been gained. Remember, "Little by
little, it's the finest meal - it's appetite for
hope..." And I agree.
--
underground experts united
http://user.it.uu.se/~embe8573
^ permalink raw reply [flat|nested] 10+ messages in thread