In Ubuntu releases prior to Ubuntu 19.10 Eoan Ermine, when I run a command with sudo
, that command receives my home directory in the $HOME
environment variable. This is the behavior I have long expected and warned other people about. If I want sudo
to reset the $HOME
environment variable, so that it refers to the target user's home directory instead of my own, I have to pass the -H
option (or -i
, though that does more).
ek@Kip:~$ lsb_release -d
Description: Ubuntu 18.04.3 LTS
ek@Kip:~$ sudo printenv HOME # Shows ek's home, not root's.
/home/ek
ek@Kip:~$ sudo -u as printenv HOME # Shows ek's home, not as's.
/home/ek
ek@Kip:~$ sudo -H printenv HOME # Shows root's home.
/root
ek@Kip:~$ sudo -Hu as printenv HOME # Shows as's home.
/home/as
When I first upgraded to Ubuntu 19.10, I was surprised to discover that sudo
seems to reset $HOME
no matter what! I continue to observe this now that 19.10 is released and I've installed updates--both on newly installed systems and one I upgraded to 19.10.
ek@Cord:~$ lsb_release -d
Description: Ubuntu 19.10
ek@Cord:~$ sudo printenv HOME # Shows root's home, even without -H or -i.
/root
ek@Cord:~$ sudo -u as printenv HOME # Shows as's home, even without -H or -i.
/home/as
ek@Cord:~$ sudo -H printenv HOME # Also shows root's home.
/root
ek@Cord:~$ sudo -Hu as printenv HOME # Also shows as's home.
/home/as
I thought this might be due to updated configuration files. But I checked, and always_set_home
does not appear in any Defaults
line in my 19.10 /etc/sudoers
file.
What makes sudo
treat $HOME
differently starting in 19.10, and why was this change made? Does this make it safe to use plain sudo
in cases where I would previously have used sudo -H
?