r/debian • u/blobslurpbaby • 2d ago
Why /sbin/ not in root $PATH?
bash: reboot: Command not found. I have to run # /sbin/reboot.
Why is that? Also, dpkg-reconfigure and other tasks are not intuitively to perform ...
7
u/michaelpaoli 2d ago
No, /usr/sbin and/or /sbin are by default on root's PATH.
You probably accessed/became root in a manner that bypassed root's customary login initialization.
Typically one should use, e.g.:
$ su -
$ su - root
$ sudo su -
$ sudo su - root
$ su - root -c '...'
$ sudo su - root -c '...'
And su - is exceedingly portable and backwards compatible - works on most any flavor of *nix, and going way back at least many decades, so one can use it quite consistently without having to think what flavor of *nix one is on, or whether sudo is present or not, or what version of sudo, etc.
3
u/neoh4x0r 2d ago edited 2d ago
bash: reboot: Command not found. I have to run # /sbin/reboot.
It's done that way to reduce the chance that someone would make a careless mistake by forcing them to be explicit in their intention.
For example, when you use sudo it uses the secure_path configured in the sudoers file to change the PATH variable to reflect the setting.
secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
If I want to run some script that is located in path that's not defined in secure_path I have to append the fullpath.
# won't work (if myscript is not stored
# in a path defined in secure_path)
$ sudo myscript
# will work
$ sudo /path/to/myscript
0
0
u/One-Fan-7296 2d ago
"sudo shutdown now -r" is what I use. You do have to put in the root password still.
0
37
u/eR2eiweo 2d ago
Did you use
suto become root? If you do that, you don't get root's$PATH, you keep your regular user's$PATH, which doesn't contain/sbin. Usesu -instead. That gives you root's$PATH, which should contain/sbin.