For the 1st question:
What security risk is posed by not requiring this to have root privileges? The GUI provides a way for any user to shut off or restart, so why do the terminal commands need to be run as root?
Yes, as said in this answer, Linux is inherently designed as multiuser system. Consider more than one user are working on a system, then it would be bad if any one normal user is allowed to turn-off the system while others are working. Imagine what happens if your web-server taken down by a user at a distance! So, Only system administrator aka root-user is allowed to poweroff
or reboot
the system.
You can also figure-out:
$ which poweroff reboot
/sbin/poweroff
/sbin/reboot
So, poweroff
and reboot
are located under /sbin
directory which holds the utilities and root-only commands, essential binaries for booting, restoring, recovering, and/or repairing the system.
So, these commands are expected to be run by system-administrator/root user, visit the manpage:
DESCRIPTION
These programs allow a system administrator to reboot, halt or poweroff the system.
Also visit related question: Why do we need to be root in terminal for shutdown and restart?
For the 2nd question:
Speaking of the options from the GUI, if the terminal requires root privileges to shut off or restart the Linux computer, how is the GUI able to present an option that does the same without requiring the entering of a password?
GUI is a matter of convenience and obviously user logged into GUI, knows what's going on and what s/he is doing. So, it doesn't expect password prompt/requirement from user i.e allowed to be shut-down or reboot through some mechanism like policy-kit. But in case of command-line the things are quit different...
Of course, you can use equivalent command provided by Desktop-Environment. Example, for gnome
, you can use: gnome-session-quit
with appropriate option which doesn't require root privileges.
Also visit related question: How does the power button shut the computer down without root permission?
pam_console
. – chexum Jan 07 '16 at 08:46gnome-session-quit --poweroff --force
will shut you down without being root. – Naftuli Kay Jan 08 '16 at 09:32systemd
, a user on the terminal can shutdown and reboot without root privileges, using the commandssystemctl poweroff
andsystemctl reboot
. This will ask for authentication using polkit if you're on a remote login or your policy otherwise requires it, but otherwise doesn't require any special privilege. – vurp0 Jan 11 '16 at 09:08