2

In troubleshooting vi, I noticed on my Ubuntu installation running the command sudo env | grep HOME returns the home directory of the user that runs the command (/home/USER). But I noticed on my Linux Mint installation running the command sudo env | grep HOME returns /root. I have looked at /etc/sudoers on both computers and they are identical except for a Defaults mailto= entry. They both have Defaults env_reset. How does sudo determine how to set the HOME environment variable? I've seen elsewhere (https://unix.stackexchange.com/a/174587/471273) that sudo -V tells you which environment variables are preserved, but on both computers it just told my the sudo version and the plugins it was installed with. I also see in the sudo man page this section which makes me thing I need to ask how to view the security policy which I don't know how to do.

 -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.

This is causing problems with loading .vimrc when I run vim as sudo. I could copy the .vimrc to the /root directory, but I am curious about this behavior and about sudo.

2

1 Answer 1

4

Ubuntu included a patched version of sudo that preserved $HOME after sudo changed env preservation sometime around 2011 (as far as I can tell... sudo's changelog is a mess). Most other distros didn't patch that. But in Ubuntu 19.10 they changed to the upstream behavior, so it's interesting that your Ubuntu machine still has the old behavior (unless you just haven't updated in a long time, or overrode that somewhere).

1
  • I'm using Ubuntu 18.04.6 LTS but support for it ends April 2023. So I guess it's time to upgrade. I keep finding nuances to sudo so thank for explaining.
    – geckels1
    Commented Mar 12, 2023 at 1:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .