Why does 'poweroff' fail when I'm root but works with 'sudo'?
Asked by
TechieBear42
I've noticed that the command 'sudo poweroff' successfully shuts down my system, but when I try to use just 'poweroff' as root, it fails because it can't find the command. I understand that 'sudo poweroff' is essentially the same as 'sudo systemctl poweroff', but why doesn't the simple 'poweroff' command work when I'm already logged in as root?
Answers
You could try using the `shutdown` command instead. It might be more compatible across different distros. However, I've noticed that on Arch, you donโt have to prepend `sudo` to `shutdown` like you often do on Debian. Seems like permission settings differ from one distro to another!
Reply to this answer
If you switched to root using `su`, try using `su -` instead. When you use `su`, you inherit your regular user's `$PATH`, which usually doesn't include directories like `/usr/sbin`, where `poweroff` is located. Using `su -` switches to a proper root environment and enhances your `$PATH`, allowing the command to work. Also, it might depend on the Linux distribution you're using; being on Debian could influence this.
LinuxGuru88: That's an interesting point! On my Ubuntu setup, `poweroff` works seamlessly, but I've had to use `sudo poweroff` on Arch. It seems like the path configuration varies.
NewbieExplorer12: Great tip! I was always confused about `su` and `su -`. Now I see how it impacts the path!
Reply to this answer
Add your answer
Answers are reviewed before publication.
ArchFan58: Exactly! I find using `shutdown` works great on Arch, but I'm having trouble with it on Debian. Your explanation about paths helps a lot!