Why sudo is needed for rebooting in terminal but not from the GUI?

10

When I turn on my machine and I log in to my account I can do whatever I want and even shutdown my machine or say reboot.

But if I open terminal and try to run the command reboot or shutdown then I need to have root access. Why is this so?

I can think of some reasons this kind of behavior like for you may find it desirable for ssh but I am not sure about it, or I can be totally missing some point.

Aman Deep Gautam

Posted 2012-09-20T17:05:54.900

Reputation: 225

Check up on dbus and your graphical environtment (e.g. KDE or gnome). – Hennes – 2012-09-20T17:08:02.557

I think you can do it on every gui, I just want to know why such design feature is there. – Aman Deep Gautam – 2012-09-20T17:11:02.463

Answers

6

Its a safety feature.

When using the GUI, you are (typically) sitting in front of the computer you are working on. However, when using a terminal, you might be physically on one machine and remotely using another. You might have many terminal windows open to many different machines. What if you accidentally type reboot in the wrong one? That action could range from an inconvenience to a complete disaster.

By using sudo it forces you to use a password. If you type in the wrong password it gives you an error and hopefully you realize that you are in the wrong terminal. This is why its good practice to have a different root password on every server.

Keltari

Posted 2012-09-20T17:05:54.900

Reputation: 57 019

@StevenLu Check your paths. ("echo ${PATH}") It could likely be that an "sbin" directory is not in your path in some cases. In that case, the weirdness might not be with the reboot command. Using "which reboot" might also help to explain. – TOOGAM – 2015-09-28T19:14:55.483

I also thought the same but just wanted to make sure that I am not missing something..:) – Aman Deep Gautam – 2012-09-20T17:28:29.683

1Ive seen more than a few Unix admins remove the computer name from their shell prompts because it took up to much space and later regret that decision. – Keltari – 2012-09-20T17:33:02.440

Note that is not exactly a safety feature in the sense understood here. When Unix started, you only got consoles (no GUI). And only the root user had permission to shutdown/restart. It is still that way. The GUI bypasses using the +s bit in files. Although you can remove those in your menu using these commands: http://askubuntu.com/questions/53308/remove-shutdown-suspend-restart-and-hibernate-from-the-user-switcher-menu

– Alexis Wilke – 2012-12-27T08:50:42.757

I just saw my CentOS VM claim "reboot" was not a command when I was su-ed as root. I typed sudo reboot there and it worked. When I directly SSH in as root, reboot works fine. It's weird. – Steven Lu – 2013-07-25T05:31:16.270

0

You can usually reboot from the terminal by pressing Ctrl+Alt+Del. That doesn't work remotely. (Rebooting remotely from the GUI without privileges doesn't work either.)

Joshua

Posted 2012-09-20T17:05:54.900

Reputation: 619