7

I installed the latest version of Debian (netinstall).
I have the problem, that the terminal does not know commands like shutdown, reboot, and so on.
When I do whereis shutdown it tells me it is in /usr/sbin.

I fixed this on a different installation try by writing /usr/sbin into /etc/profile where the $PATH is written.
But this time it did not work.

I looked at this: https://wiki.debian.org/EnvironmentVariables, but either those files did not exist or I did not know where to put the path.
And doing export PATH=$PATH:usr/sbin is not permanent, it's gone after reboot, so that is garbage as well.

Edit: Wait, maybe I have to change the PATH in /etc/environment?!
I have to test this once I give Debian another try.

  • 1
    You usually don't have the sbin directories in the PATH for a regular user, since the stuff isn't that usable for a regular user. Though with Policykit or such, shutdown could be. So I guess an important part here is if it's just the search path or not -- does shutdown work for you if you run it as /usr/bin/shutdown? For the path, see e.g. How do I set a user environment variable? (permanently, not session) – ilkkachu Mar 24 '21 at 11:11
  • 1
    I can do /usr/sbin/shutdown now as root, but I want to use the commands without the whole path like in Ubuntu of course... – theerrormagnet Mar 24 '21 at 11:24
  • 4
    I notice that you use usr/sbin as the path, without the initial /. You may want to make sure that your path contains /usr/sbin rather than usr/sbin, and that /etc/profile is correct too. Note also that you probably want to mention what shell you're using too, as some shells don't care about /etc/profile (e.g. zsh). – Kusalananda Mar 24 '21 at 11:31
  • Note that with the latest debian you might prefer the systemd-way in the first place: systemctl poweroff - you could alias this. – FelixJN Mar 24 '21 at 11:37
  • You will have to be more specific about what you did to /etc/profile to diagnose what you did wrong. Debian annoyingly defaults to only giving root sbin on the path, so I always remove the test for root from /etc/profile. – psusi Mar 24 '21 at 18:16
  • I did use the initial /before usr/sbin. I have now switched back to Ubuntu, it has /usr/sbin in its path by default. But I'm still clueless why it doesn't work in Debian. – theerrormagnet Mar 24 '21 at 23:47

5 Answers5

10

Binaries in the /sbin and /usr/sbin directories are intended to be run only be superusers/sudoers. If you want to run anything in there, prefix your command with sudo. Your user will need to be a member of the sudoers group though.

$ sudo shutdown -P +0

For proof of concept, try which shutdown vs sudo which shutdown.

  • which shutdown outputs nothing. sudo which shutdown outputs: testuser is not in the sudoers file. This incident will be reported. – theerrormagnet Mar 25 '21 at 08:41
  • 1
    That means your account isn't allowed to use sudo. If you're sure you want to, you can add the user to the sudo group with usermod -aG sudo <username>, but you'll have to do this on the root account (enter su to switch to the root account), or at least another account that can run sudo. – Ashley Miller Mar 25 '21 at 11:38
3

Figured it out, you were on the right path with export PATH="$PATH:/usr/sbin". What you have to do is edit your .bashrc file, and put export PATH="$PATH:/usr/sbin" at the bottom, save, close. Then it'll work permanently.

Kusalananda
  • 333,661
2

SystemD, through the polkit auth agent, allows you to execute those commands (shutdown/reboot...) transparently:

systemctl poweroff

shuts down the system.

You can even make a Bash alias:

alias shutdown="systemctl poweroff"

And then use shutdown transparently.

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
1

I have installed "sudo" in debian 11. Then I tried again "shutdown -r now" and the problem has solved.

Tobias
  • 11
  • Welcome to the site, and thank you for your contribution. Please note that your answer seems to reiterate what was already stated in the accepted answer, except for noting that you needed to install an additional package to implement it. As such, you should consider posting it as a comment below that answer (once you have sufficient reputation) or submit an edit suggestion. – AdminBee Nov 17 '21 at 14:23
  • I upvoted by accident. This is not the correct answer. Correct answer is updating the PATH to include /usr/sbin – Timothy C. Quinn Feb 05 '24 at 22:15
0

Debian - Unable to shutdown/reboot my Debian ("bash: shutdown: command not found")

Log as root and perform...

echo '
export PATH="$PATH:/usr/sbin"
' | tee -a /root/.bashrc

... or explicitly tell the su to set environment variable as if the user logs in directly...

su -

EXTRA:

Add an user to the sudo group with

usermod -aG sudo <USERNAME>

Do this as root (or root capable) account.

[Ref(s).: https://unix.stackexchange.com/a/664942/61742 , https://superuser.com/a/1539749/195840 ]