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

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.


Solution 1:

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.