I've noticed something interesting: when I use 'sudo poweroff', it shuts down the system just fine. However, if I'm already logged in as root and try to run 'poweroff' on its own, I get an error saying the command can't be found. I'm aware that 'sudo poweroff' is essentially the same as 'sudo systemctl poweroff', but why doesn't the standalone 'poweroff' command work?
4 Answers
You know, I’ve noticed something different between distros. On Ubuntu, 'poweroff' works directly as a root user, while on Arch it sometimes requires 'sudo'. The location of binaries in the PATH plays a big role. So, it may vary depending on your system setup.
True! I never thought about it that way, but it explains a lot.
When you're using 'su' to switch to root, it doesn't automatically set up your environment the same way as logging in directly as root would. This can affect the $PATH variable, which determines where your shell looks for commands. For example, 'poweroff' is located in '/usr/sbin', which is typically included in the root user's $PATH but not for normal users. If you want to get the root environment, you should use 'su -' instead of just 'su'. That way, your shell will locate 'poweroff' without problems.
That’s a great point! I’ve had similar issues before. Using 'su -' makes a huge difference.
Good to know! I've always just used 'su'. I'll try 'su -' next time.
If you're still having trouble, you might consider using 'shutdown' as an alternative. It works well, although it behaves slightly differently than 'poweroff'. Just a thought!
Thanks for the tips, everyone! I've realized that I often default to using 'sudo' without considering other ways to switch to root. I’ll give 'su -' and other commands a try next time!

That makes sense! Different distributions prioritize user permissions in their own ways.