5

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.

theerrormagnet
  • 79
  • 1
  • 1
  • 9
  • 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)](https://unix.stackexchange.com/q/21598/170373) – 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

5

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.

Ashley Miller
  • 201
  • 1
  • 1
  • `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 `, 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
  • 320,670
  • 36
  • 633
  • 936
Thundercat
  • 31
  • 1
1

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

0

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

Tobias
  • 1
  • 1
  • 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
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 ]

Eduardo Lucio
  • 664
  • 2
  • 13
  • 34