unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Emacs creates emacs.d/ as root when using sudo
@ 2019-07-01 18:01 Jeffrey Walton
  2019-07-02  4:21 ` Stefan Monnier
  2019-07-02  6:16 ` Teemu Likonen
  0 siblings, 2 replies; 9+ messages in thread
From: Jeffrey Walton @ 2019-07-01 18:01 UTC (permalink / raw)
  To: emacs-devel

Hi Everyone,

I think this is unexpected behavior:

    $ sudo apt-get install emacs-nox
    $ sudo emacs /etc/default/motd-news
    $ ls -Al ~ | grep emacs
    $ drwx------  2 root    root     4096 Jul  1 13:56 .emacs.d

Then, when I use emacs as non-sudo, I am nagged with:

    Warning (initialization): Unable to access `user-emacs-directory'
(~/.emacs.d/)

I think emacs should be creating files in user's $HOME as $SUDO_USER,
not root. Or, emacs should be creating .emacs.d/ in /root, not user's
$HOME.

Jeff



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Emacs creates emacs.d/ as root when using sudo
  2019-07-01 18:01 Emacs creates emacs.d/ as root when using sudo Jeffrey Walton
@ 2019-07-02  4:21 ` Stefan Monnier
  2019-07-02  6:34   ` Andreas Schwab
  2019-07-02  6:16 ` Teemu Likonen
  1 sibling, 1 reply; 9+ messages in thread
From: Stefan Monnier @ 2019-07-02  4:21 UTC (permalink / raw)
  To: emacs-devel

>     $ sudo emacs /etc/default/motd-news

I'd consider the above as a pilot error.

If you use sudo naively like above, the $HOME is still that of the
invoking user, so you're going to have these kinds of problems with all
kinds of programs (I also consider it a serious security issue because
you'll execute as root the user's ~/.emacs or in other cases it'll be
the user's ~/.bashrc or whatever else, and I'd generally assume that
those files were not written under the assumption that they may be run
as root, so they may introduce all kinds of problems).


        Stefan




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Emacs creates emacs.d/ as root when using sudo
  2019-07-01 18:01 Emacs creates emacs.d/ as root when using sudo Jeffrey Walton
  2019-07-02  4:21 ` Stefan Monnier
@ 2019-07-02  6:16 ` Teemu Likonen
  1 sibling, 0 replies; 9+ messages in thread
From: Teemu Likonen @ 2019-07-02  6:16 UTC (permalink / raw)
  To: Jeffrey Walton; +Cc: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 1467 bytes --]

Jeffrey Walton [2019-07-01 14:01:58-04:00] wrote:

> I think emacs should be creating files in user's $HOME as $SUDO_USER,
> not root. Or, emacs should be creating .emacs.d/ in /root, not user's
> $HOME.

This is about sudo's settings, not Emacs's. See sudo's option "-H" (man
sudo):


    -H, --set-home
                Request that the security policy set the HOME
                environment variable to the home directory specified by
                the target user's password database entry. Depending on
                the policy, this may be the default behavior.


Or "man sudoers":


     always_set_home   If enabled, sudo will set the HOME environment vari‐
                       able to the home directory of the target user (which
                       is root unless the -u option is used).  This effec‐
                       tively means that the -H option is always implied.
                       Note that by default, HOME will be set to the home
                       directory of the target user when the env_reset
                       option is enabled, so always_set_home only has an
                       effect for configurations where either env_reset is
                       disabled or HOME is present in the env_keep list.
                       This flag is off by default.



-- 
/// Teemu Likonen   <https://github.com/tlikonen> //
// PGP: 4E1055DC84E9DFF613D78557719D69D324539450 ///

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Emacs creates emacs.d/ as root when using sudo
  2019-07-02  4:21 ` Stefan Monnier
@ 2019-07-02  6:34   ` Andreas Schwab
  2019-07-02 15:02     ` Stefan Monnier
  2019-07-02 15:27     ` Lars Ingebrigtsen
  0 siblings, 2 replies; 9+ messages in thread
From: Andreas Schwab @ 2019-07-02  6:34 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

On Jul 02 2019, Stefan Monnier <monnier@iro.umontreal.ca> wrote:

>>     $ sudo emacs /etc/default/motd-news
>
> I'd consider the above as a pilot error.
>
> If you use sudo naively like above, the $HOME is still that of the
> invoking user,

It's really a misconfiguration of sudo if it doesn't reset HOME.

Andreas.

-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Emacs creates emacs.d/ as root when using sudo
  2019-07-02  6:34   ` Andreas Schwab
@ 2019-07-02 15:02     ` Stefan Monnier
  2019-07-02 15:27     ` Lars Ingebrigtsen
  1 sibling, 0 replies; 9+ messages in thread
From: Stefan Monnier @ 2019-07-02 15:02 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: emacs-devel

>>>     $ sudo emacs /etc/default/motd-news
>> I'd consider the above as a pilot error.
>> If you use sudo naively like above, the $HOME is still that of the
>> invoking user,
> It's really a misconfiguration of sudo if it doesn't reset HOME.

Oh, indeed, I was confusing it with `su`.
That confirms it's not a problem on Emacs's side.


        Stefan




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Emacs creates emacs.d/ as root when using sudo
  2019-07-02  6:34   ` Andreas Schwab
  2019-07-02 15:02     ` Stefan Monnier
@ 2019-07-02 15:27     ` Lars Ingebrigtsen
  2019-07-02 16:29       ` Eli Zaretskii
  1 sibling, 1 reply; 9+ messages in thread
From: Lars Ingebrigtsen @ 2019-07-02 15:27 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: Stefan Monnier, emacs-devel

Andreas Schwab <schwab@suse.de> writes:

>>>     $ sudo emacs /etc/default/motd-news
>>
>> I'd consider the above as a pilot error.
>>
>> If you use sudo naively like above, the $HOME is still that of the
>> invoking user,
>
> It's really a misconfiguration of sudo if it doesn't reset HOME.

But, by default, sudo doesn't (on Ubuntuish systems).

Emacs is somewhat unusual among editors you might fire up as root in
that it might create or write files and directories in $HOME without the
user knowing, and that leads to frustration and makes "# emacs -nw" less
comfortable than it could be.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Emacs creates emacs.d/ as root when using sudo
  2019-07-02 15:27     ` Lars Ingebrigtsen
@ 2019-07-02 16:29       ` Eli Zaretskii
  2019-07-02 17:16         ` Lars Ingebrigtsen
  0 siblings, 1 reply; 9+ messages in thread
From: Eli Zaretskii @ 2019-07-02 16:29 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: schwab, monnier, emacs-devel

> From: Lars Ingebrigtsen <larsi@gnus.org>
> Date: Tue, 02 Jul 2019 17:27:49 +0200
> Cc: Stefan Monnier <monnier@iro.umontreal.ca>, emacs-devel@gnu.org
> 
> Emacs is somewhat unusual among editors you might fire up as root in
> that it might create or write files and directories in $HOME without the
> user knowing

Doesn't the shell (e.g., Bash) do the same by putting there
.bash_history etc.?



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Emacs creates emacs.d/ as root when using sudo
  2019-07-02 16:29       ` Eli Zaretskii
@ 2019-07-02 17:16         ` Lars Ingebrigtsen
  2019-07-02 17:58           ` Stefan Monnier
  0 siblings, 1 reply; 9+ messages in thread
From: Lars Ingebrigtsen @ 2019-07-02 17:16 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: schwab, monnier, emacs-devel

Eli Zaretskii <eliz@gnu.org> writes:

> Doesn't the shell (e.g., Bash) do the same by putting there
> .bash_history etc.?

It does, but most people already have a .bash_history (and the ownership
won't change), so that's not a problem in practice in my experience...

(While I've had to chown plenty of .emacs/.emacs.d files in my time.)

I'm not saying we should change anything here, really -- but it's a
problem in practice that other editors, like vim, isn't as prone to
being affected by.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Emacs creates emacs.d/ as root when using sudo
  2019-07-02 17:16         ` Lars Ingebrigtsen
@ 2019-07-02 17:58           ` Stefan Monnier
  0 siblings, 0 replies; 9+ messages in thread
From: Stefan Monnier @ 2019-07-02 17:58 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: schwab, Eli Zaretskii, emacs-devel

> (While I've had to chown plenty of .emacs/.emacs.d files in my time.)
> I'm not saying we should change anything here, really -- but it's a
> problem in practice that other editors, like vim, isn't as prone to
> being affected by.

I think the real problem is that Emacs is a bit too eager to create
~/.emacs.d.  It should ideally try and delay this as much as possible.

At the same time, it helps keep things simple to create it (and files
within it) freely.


        Stefan




^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2019-07-02 17:58 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-07-01 18:01 Emacs creates emacs.d/ as root when using sudo Jeffrey Walton
2019-07-02  4:21 ` Stefan Monnier
2019-07-02  6:34   ` Andreas Schwab
2019-07-02 15:02     ` Stefan Monnier
2019-07-02 15:27     ` Lars Ingebrigtsen
2019-07-02 16:29       ` Eli Zaretskii
2019-07-02 17:16         ` Lars Ingebrigtsen
2019-07-02 17:58           ` Stefan Monnier
2019-07-02  6:16 ` Teemu Likonen

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).