pkexec unconditionally calls chdir(~)
sudo COMMAND ARGS
preserves the current working directory when running COMMAND ARGS
as root
; pkexec COMMAND ARGS
changes to root
's home directory. This behaviour was introduced when this command was first added, in c8c3d835 (more than 10 years ago), without explanation.
I find this annoying because it means dpkg-buildpackage -uc -us -b && pkexec dpkg -i ../foo_*.deb
does not work. (I'm not using sudo
because I am experimenting with using my computer as an unprivileged user, relying on polkit to prompt me to authenticate as the administrator user on this system, to see what breaks.)
I can't see a strong security justification for not preserving the current working directory, but I'm sure I've overlooked something!