Bug 797 - sudo not changing to user's home
sudo not changing to user's home
Status: RESOLVED FIXED
Product: Sudo
Classification: Unclassified
Component: Sudo
1.8.15
IBM AIX
: low normal
Assigned To: Todd C. Miller
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2017-08-30 07:07 MDT by Henrik Morsing
Modified: 2020-09-22 07:46 MDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Henrik Morsing 2017-08-30 07:07:14 MDT
Using -H or always_set_home still preserves root's home directory:

--> sudo -V
Sudo version 1.8.15
[...]
Environment variables to preserve:
        XAUTHORIZATION
        XAUTHORITY
        PS2
        PS1
        PATH
        LS_COLORS
        KRB5CCNAME
        HOSTNAME
        DISPLAY
        COLORS
[...]
--> sudo -H -u metron pwd
/
--> sudo -u metron ksh
$ pwd
/
$

We have had this problem with 1.6.9p15 for years, decided to upgrade, but 1.8.15 does the same.

Thanks
Comment 1 Todd C. Miller 2017-08-30 09:12:09 MDT
Sudo has never changed the current working directory but this is unrelated to the value of the HOME environment variable.

If you run "sudo -u metro printenv HOME" you will see that it is being set to the proper value.

I'm leaving this bug open since it would be useful to have an option that changes the cwd to the destination user's home directory.
Comment 2 Daniele Palumbo 2017-12-06 18:15:34 MST
+1 on this
Comment 3 Todd C. Miller 2020-09-22 07:46:03 MDT
In sudo 1.9.3 you can set the CWD on a per-rule basis or globally.  For example, to always run commands in the target user's homedir you can use:

Defaults runcwd=~

where '~' stands for the user's homedir.