After executing su command, shouldn't sbin be in path

While attempting to debug my sshd a few days back I ran into an interesting situation that I’m not sure what the correct answer is.

Per the man page ‘su root’ creates an interactive shell with the root user. However, doing a ‘which sshd’ in the su shell returns nothing, and further debugging shows sbin is missing from the path.

So the question is should the sbin be added to the path when ‘su root’ or should it inherit the existing path from the current shell?

Here’s the interaction showing paths immediately after login and subsequent switch ‘su root’:

dietpi@n2:~$ which sshd
dietpi@n2:~$ bash -c 'echo $PATH'
/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
dietpi@n2:~$ sudo bash -c 'echo $PATH'
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
dietpi@n2:~$ dash -c 'echo $PATH'
/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
dietpi@n2:~$ sudo dash -c 'echo $PATH'
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
dietpi@n2:~$ su root
Password:

root@n2:/home/dietpi# which sshd
root@n2:/home/dietpi# bash -c 'echo $PATH'
/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
root@n2:/home/dietpi# sudo bash -c 'echo $PATH'
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
root@n2:/home/dietpi# dash -c 'echo $PATH'
/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
root@n2:/home/dietpi# sudo dash -c 'echo $PATH'
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
root@n2:/home/dietpi# 

Note that root user doesn’t have access to sbin, whereas executing command via sudo does…

  • DietPi version | G_DIETPI_VERSION_CORE=9
    G_DIETPI_VERSION_SUB=11
    G_DIETPI_VERSION_RC=2
    G_GITBRANCH=‘master’
    G_GITOWNER=‘MichaIng’
  • Distro version | bookworm
  • Kernel version | Linux n2 6.6.65-current-meson64 #1 SMP PREEMPT Wed Dec 11 15:13:43 UTC 2024 aarch64 GNU/Linux
  • SBC model | Odroid N2 (aarch64)
  • Power supply used | 5V 2A
  • SD card used | SanDisk ultra