I recently found out that reboot works just as well as sudo reboot, from what I can tell. However, in a lot of instances, I see people saying to sudo reboot. Why is this? Are they the same, and just personal preference? Or are they different? Does sudo reboot do more than reboot?
- 39,392
- 12
- 115
- 163
- 923
- 1
- 6
- 11
-
`sudo` is short for "Super-user Do". It has no effect on the command itself (this being `reboot`), it merely causes it to run as the super-user rather than as you. It is used to do things that you might not otherwise have permission to do, but doesn't change what gets done. If you already have permission to run `reboot`, then fine, just run `reboot`. – Lee Crocker Feb 15 '18 at 00:26
-
This traditionally needs root to do. Old habits break hard. – Thorbjørn Ravn Andersen Feb 15 '18 at 09:48
-
1Rebooting system by the regular user does not even sound logical. Changing runlevel of the root process (init) should be possible by root and only root user. You cannot even access filesystems shortcuts of sysrq by any other user. BUT ! You can reboot your linux by `sysrq` [keys](https://en.wikipedia.org/wiki/Magic_SysRq_key), it does not require `sudo` :) – Svetlana Linuxenko Feb 14 '18 at 10:22
-
6@SvetlanaLinuxenko > *Rebooting system by the regular user does not even sound logical* The user who is sitting at the console can just hit the power button or pull the plug if we don't let them cleanly reboot. – Kaz Feb 15 '18 at 22:58
-
A lot of **other** distributions won't let you reboot if you're not root. – user253751 Feb 15 '18 at 23:46
-
Obligatory [XKCD](https://xkcd.com/149/). – Patrick Roberts Feb 18 '18 at 02:00
5 Answers
On Ubuntu 14.10 and older, sudo is required.
The introduction of Systemd in 15.04 changed the way Ubuntu handles shutdown and reboot:
When a single user is logged in,
sudoisn't necessary. When more than one user is logged in thensudois required.Applications can inhibit
shutdownandreboot. You override these inhibitions withsudo.A single user logged in via
sshstill requiressudo.
- 58,040
- 10
- 106
- 136
-
-
8It has nothing to do with the number of users connected. The ability to reboot without using `sudo` is dependent on being at the machine's console. If you ssh into a machine, you still won't be able to reboot it without `sudo`, even if you're the only user logged in. Conversely, if you're at the console, you can still reboot without `sudo` even if other users are connected remotely. – Dave Sherohman Feb 14 '18 at 11:47
-
3@DaveSherohman: That's not necessarily true -- systemd still uses [separate polkit actions](https://github.com/systemd/systemd/blob/master/src/login/org.freedesktop.login1.policy.in#L190-L210) depending on whether you're the only person logged in, or whether there are multiple. Meaning, the distro (or the sysadmin) could very easily make them behave differently. – user1686 Feb 14 '18 at 19:20
On my 14.04 machine, when I (as a normal user) type reboot, I get
reboot: Need to be root
That is the difference.
As Terrance pointed out in the comments, it works differently on later systems than mine. So you are probably seeing old writeups and/or users (like me) who have been habituated to typing sudo reboot!
- 22,803
- 12
- 65
- 118
-
Interesting! What I am wondering now, is if something changed between 14.04 and 17.10 to make it that you don't need to be root to `reboot`, or if there are other factors in play on my system changing that. – Zeke Egherman Feb 13 '18 at 19:06
-
3@ZekeEgherman I actually think the difference happened when they changed from Upstart to Systemd for the commands. When I look at my reboot command it points as a link to `/bin/systemctl`. You can check yours by typing in `ls -al $(which reboot)`. – Terrance Feb 13 '18 at 19:07
-
@terrance, I also see the link to `/bin/systemct1`, what version are you? – Zeke Egherman Feb 13 '18 at 19:08
-
That is interesting! I just tried it on my 18.04 pre-release virtual machine, and it works as you say. @Terrance, I think you should write up the real answer. – Organic Marble Feb 13 '18 at 19:08
-
@ZekeEgherman 16.04. Ubuntu switched to Systemd at 15.04. So, 14.04 would still be Upstart then or initd if that is what you want to call it. – Terrance Feb 13 '18 at 19:10
-
-
I'm not even an old-timer and the command that I always use is `sudo shutdown -r now`. I guess that I learned something? – hazzey Feb 13 '18 at 21:29
sudo rebootis used in tutorials / how-tos for compatibility reasons
While reboot might work
- if you are root or
- if you are on a host with
systemdand - if no applications are blocking a reboot
sudo reboot will "always"* work, regardless of
- whether you are root
- whether there are other users logged in
- whether there are applications blocking
- whether init is systemd, System V, Upstart, whatever
* Well, it will certainly try - short of there being some kernel processes that are blocking/misbehaving it should work.
- 69,223
- 56
- 216
- 327
- 4,321
- 16
- 37
For myself many times if I type reboot it won't let me due to inhibitors from Chrome when watching YouTube and other opened tabs. So I'm forced to use sudo reboot--a bigger hammer.
This in Ubuntu 16.04
- 99,709
- 34
- 237
- 401
Thanks for the discussion, I'm glad to understand this now!
As Terrance mentioned, in version 15.04, they switched from Upstart to Systemd for the commands. This change means that reboot no longer requires root privileges.
As for why the *nix community instructs to sudo reboot, there are a few potential reasons:
- Habit - People were so used to having to
sudo rebootto reboot, they continue to do it despite the fact it is not needed Non-updated users - The people instructing to
sudo rebootare on versions of Ubuntu lower than 15.04, or other distros that use Upstart for commands.Compatibility - This is what seems the most plausible to me: people are instructing to
sudo rebootbecause it is guaranteed to reboot across all *nix systems, no matter what.
Additional note: from user535733's answer:
The introduction of systemd in 15.04 changed the way Ubuntu handles shutdown and reboot:
When a single user is logged in,
sudoisn't necessary. When more than one user is logged in, thensudois required.Applications can inhibit shutdown and reboot. You override these inhibitions with
sudo.
- 923
- 1
- 6
- 11