kassube at gmx.net
Mon Jun 9 18:58:42 UTC 2014
Tom H wrote:
> On Mon, Jun 9, 2014 at 9:48 AM, Nils Kassube <kassube at gmx.net> wrote:
> > With "sudo su" I have $HOME set
> > to "/root" while it is still "/home/$USER" for "sudo -s". That is
> > an important difference if I then start an application that
> > modifies configuration files and changes their permissions in
> > $HOME. It may therefore prevent further access to those files by
> > the original user and the application run as normal user may no
> > longer work.
> I'd never noticed that Ubuntu HOME isn't set to the target user's
> The upstream default (that's not changed in RHEL and Fedora for
> example, and perhaps not in other distributions) is for HOME to be
> reset to the target user's HOME.
> It turns out that there's a patch in Ubuntu (it might be inherited
> from Debian, I haven't checked), "keep_home_by_default", to keep HOME.
> I wonder what the rationale is/was.
Good question. IMHO it isn't useful, but what do I know. I don't think
it comes from Debian. I just checked the "sudo -s" behaviour on a
Raspberry Pi running Raspbian which is also derived from Debian. But
there $HOME is always set to "/root".
> This behavior contradicts the sudoers man page as well as
> "/usr/share/doc/sudo/README.Debian"  and it can be overridden with
> "-H" when invoking sudo and with "Default always_keep_home" or
> "Defaults env_keep -= "HOME"" in "/etc/sudoers" or "/etc/sudoers.d/".
At least it is documented at
| To start a root shell, but keep the current shell's environment, use:
| sudo -s (similar to sudo su)
And I suppose that's where I learned about this behaviour. But it would
certainly be nice if there was a hint in the man page.
> "sudo -s" doesn't change the ownership of already exiting files in
> HOME but creates new ones as "root:root"...
Right, that makes sense.
More information about the ubuntu-users