<SOLVED> Terminal commands "shutdown now" and "reboot now"

Questions about other topics - please check if your question fits better in another category before posting here
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
User avatar
senjoz
Level 5
Level 5
Posts: 901
Joined: Tue Jun 09, 2020 3:55 am
Location: Kamnik

<SOLVED> Terminal commands "shutdown now" and "reboot now"

Post by senjoz »

Terminal command shutdown now shuts the computer down. Terminal command reboot now should reboot the computer. But this command requires sudo elevated privileges. To reboot from terminal one must use sudo reboot now.

Why rebooting requires elevated privileges?

Regards, Jože


Code: Select all

~$ inxi -Fxxxrz
System:
  Kernel: 6.1.0-1004-oem arch: x86_64 bits: 64 compiler: N/A Desktop: Cinnamon
    v: 5.6.7 tk: GTK v: 3.24.33 wm: muffin vt: 1 dm: startx
    Distro: Linux Mint 21.1 Vera base: Ubuntu 22.04 jammy
Machine:
  Type: Laptop System: FUJITSU CLIENT product: LIFEBOOK A3511 v: N/A
    serial: <superuser required> Chassis: type: 10 serial: <superuser required>
  Mobo: FUJITSU CLIENT model: FJNBB73 v: EQAA023236
    serial: <superuser required> UEFI: FUJITSU CLIENT v: Version 1.09
    date: 02/18/2022
Battery:
  ID-1: BAT1 charge: 33.4 Wh (79.5%) condition: 42.0/45.0 Wh (93.2%)
    volts: 11.8 min: 10.8 model: PAC CP753347-01 type: Li-ion serial: <filter>
    status: not charging
CPU:
  Info: dual core model: 11th Gen Intel Core i3-1115G4 bits: 64 type: MT MCP
    smt: enabled arch: Tiger Lake rev: 1 cache: L1: 160 KiB L2: 2.5 MiB
    L3: 6 MiB
  Speed (MHz): avg: 2367 high: 3115 min/max: 400/4100 cores: 1: 3115 2: 1999
    3: 1357 4: 3000 bogomips: 23961
  Flags: avx avx2 ht lm nx pae sse sse2 sse3 sse4_1 sse4_2 ssse3 vmx
Graphics:
  Device-1: Intel vendor: Fujitsu Client driver: i915 v: kernel arch: Gen-12.1
    ports: active: eDP-1 empty: DP-1,HDMI-A-1,HDMI-A-2 bus-ID: 00:02.0
    chip-ID: 8086:9a78 class-ID: 0300
  Device-2: Chicony FJ Camera type: USB driver: uvcvideo bus-ID: 3-7:3
    chip-ID: 04f2:b6a0 class-ID: 0e02
  Display: server: X.Org v: 1.21.1.3 with: Xwayland v: 22.1.1 driver: X:
    loaded: modesetting unloaded: fbdev,vesa dri: iris gpu: i915 display-ID: :0
    screens: 1
  Screen-1: 0 s-res: 1920x1080 s-dpi: 96 s-size: 508x285mm (20.00x11.22")
    s-diag: 582mm (22.93")
  Monitor-1: eDP-1 model: BOE Display 0x0700 res: 1920x1080 hz: 60 dpi: 142
    size: 344x194mm (13.54x7.64") diag: 395mm (15.5") modes: 1920x1080
  API: OpenGL v: 4.6 Mesa 22.2.5 renderer: Mesa Intel UHD Graphics (TGL GT2)
    direct render: Yes
Audio:
  Device-1: Intel Tiger Lake-LP Smart Sound Audio vendor: Fujitsu Client
    driver: sof-audio-pci-intel-tgl bus-ID: 00:1f.3 chip-ID: 8086:a0c8
    class-ID: 0401
  Sound API: ALSA v: k6.1.0-1004-oem running: yes
  Sound Server-1: PulseAudio v: 15.99.1 running: yes
  Sound Server-2: PipeWire v: 0.3.48 running: yes
Network:
  Device-1: Intel Wi-Fi 6 AX201 driver: iwlwifi v: kernel bus-ID: 00:14.3
    chip-ID: 8086:a0f0 class-ID: 0280
  IF: wlp0s20f3 state: up mac: <filter>
  Device-2: Realtek RTL8111/8168/8411 PCI Express Gigabit Ethernet
    vendor: Fujitsu Client driver: r8169 v: kernel pcie: speed: 2.5 GT/s
    lanes: 1 port: 3000 bus-ID: 07:00.0 chip-ID: 10ec:8168 class-ID: 0200
  IF: enp7s0 state: down mac: <filter>
Drives:
  Local Storage: total: 238.47 GiB used: 12.28 GiB (5.1%)
  ID-1: /dev/nvme0n1 vendor: Samsung model: MZVLQ256HAJD-00007
    size: 238.47 GiB speed: 31.6 Gb/s lanes: 4 type: SSD serial: <filter>
    rev: FXV7202Q temp: 22.9 C scheme: GPT
Partition:
  ID-1: / size: 62.44 GiB used: 12.24 GiB (19.6%) fs: ext4 dev: /dev/nvme0n1p4
  ID-2: /boot/efi size: 511 MiB used: 35.2 MiB (6.9%) fs: vfat
    dev: /dev/nvme0n1p1
Swap:
  ID-1: swap-1 type: file size: 2 GiB used: 0 KiB (0.0%) priority: -2
    file: /swapfile
Sensors:
  System Temperatures: cpu: 50.0 C mobo: N/A
  Fan Speeds (RPM): N/A
Repos:
  Packages: pm: dpkg pkgs: 2082
  No active apt repos in: /etc/apt/sources.list
  Active apt repos in: /etc/apt/sources.list.d/official-package-repositories.list
    1: deb http://packages.linuxmint.com vera main upstream import backport
    2: deb http://archive.ubuntu.com/ubuntu jammy main restricted universe multiverse
    3: deb http://archive.ubuntu.com/ubuntu jammy-updates main restricted universe multiverse
    4: deb http://archive.ubuntu.com/ubuntu jammy-backports main restricted universe multiverse
    5: deb http://security.ubuntu.com/ubuntu/ jammy-security main restricted universe multiverse
Info:
  Processes: 228 Uptime: 12m wakeups: 597 Memory: 15.3 GiB
  used: 2.08 GiB (13.6%) Init: systemd v: 249 target: multi-user (3)
  default: multi-user Compilers: gcc: 11.3.0 alt: 11/12 Shell: Bash v: 5.1.16
  running-in: gnome-terminal inxi: 3.3.24
Last edited by LockBot on Mon Aug 07, 2023 10:00 pm, edited 3 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
User avatar
coffee412
Level 8
Level 8
Posts: 2271
Joined: Mon Nov 12, 2012 7:38 pm
Location: I dont know
Contact:

Re: Terminal commands "shutdown now" and "reboot now"

Post by coffee412 »

Because they do not want me logging into AT&T email servers and shutting them down or rebooting them.

John works at a company and has to constantly log in to a server and restart a program that likes to freeze up. This program provides services for 100 employees. He is under the gun to get this done as quick as possible. These 100 employee's are all working on their spreadsheets that contain very important information about the company. John is frustrated and feeling rushed. So, To kill the program he rushes and enters

Code: Select all

Reboot
by mistake.
Ryzen x1800 Asus Prime x370-Pro 32 gigs Ram RX480 graphics
Dell PE T610, Dell PE T710
- List your hardware Profile: inxi -Fxpmrz
MeshCentral * Virtualbox * Debian * InvoiceNinja * NextCloud * Linux since kernel 2.0.36
User avatar
senjoz
Level 5
Level 5
Posts: 901
Joined: Tue Jun 09, 2020 3:55 am
Location: Kamnik

Re: Terminal commands "shutdown now" and "reboot now"

Post by senjoz »

Thank you for your comment, coffee412!

coffee412 wrote: Tue Feb 07, 2023 2:36 pm Because they do not want me logging into AT&T email servers and shutting them down or rebooting them.
But why does shutdown work without sudo? Why the difference?
User avatar
coffee412
Level 8
Level 8
Posts: 2271
Joined: Mon Nov 12, 2012 7:38 pm
Location: I dont know
Contact:

Re: Terminal commands "shutdown now" and "reboot now"

Post by coffee412 »

In my test VM, It shows everyone has permission to shutdown the computer. Makes sense kinda as its a desktop computer and you can shut it down from the main menu as the current logged in user. I think on debian (have to check) that probably might be different in a server environment.


Code: Select all

coffee@MINT20-TEST:/sbin$ ls -l shutdown
lrwxrwxrwx 1 root root 14 Apr 21  2022 shutdown -> /bin/systemctl

I had a friend in England once (long story) and he was showing me how great windows was over linux. He had setup voice control and had me on skype. He is showing how he can start programs and such and then he said "I bet you cant beat that?".

I yelled in the mic "Shutdown now".

His skype connected disconnected and he went off line.
Ryzen x1800 Asus Prime x370-Pro 32 gigs Ram RX480 graphics
Dell PE T610, Dell PE T710
- List your hardware Profile: inxi -Fxpmrz
MeshCentral * Virtualbox * Debian * InvoiceNinja * NextCloud * Linux since kernel 2.0.36
User avatar
all41
Level 19
Level 19
Posts: 9523
Joined: Tue Dec 31, 2013 9:12 am
Location: Computer, Car, Cage

Re: Terminal commands "shutdown now" and "reboot now"

Post by all41 »

Also see for systemd:
systemctl poweroff
and
systemctl reboot
how to in:
man systemctl

These also run without escalated privilege
Everything in life was difficult before it became easy.
vimes666
Level 6
Level 6
Posts: 1241
Joined: Tue Jan 19, 2016 6:08 pm

Re: Terminal commands "shutdown now" and "reboot now"

Post by vimes666 »

FYI: in LMDE5 reboot works without sudo.
If you think the issue is solved, edit your original post and add the word solved to the title.
User avatar
all41
Level 19
Level 19
Posts: 9523
Joined: Tue Dec 31, 2013 9:12 am
Location: Computer, Car, Cage

Re: Terminal commands "shutdown now" and "reboot now"

Post by all41 »

vimes666 wrote: Tue Feb 07, 2023 8:25 pm FYI: in LMDE5 reboot works without sudo.
Funny because some popular distro terminals require sudo to reboot--but don't ask for the password to prove
sudo privilege
Everything in life was difficult before it became easy.
User avatar
senjoz
Level 5
Level 5
Posts: 901
Joined: Tue Jun 09, 2020 3:55 am
Location: Kamnik

Re: Terminal commands "shutdown now" and "reboot now"

Post by senjoz »

vimes666 wrote: Tue Feb 07, 2023 8:25 pm FYI: in LMDE5 reboot works without sudo.
My LMDE5 installation requires sudo for terminal command reboot now. Command shutdown now works without sudo. The same is in Manjaro. PCLinuxOS behaves differently, it is an SysVinit system.
Last edited by senjoz on Wed Feb 08, 2023 5:52 pm, edited 1 time in total.
vimes666
Level 6
Level 6
Posts: 1241
Joined: Tue Jan 19, 2016 6:08 pm

Re: Terminal commands "shutdown now" and "reboot now"

Post by vimes666 »

senjoz wrote: Wed Feb 08, 2023 12:06 pm
vimes666 wrote: Tue Feb 07, 2023 8:25 pm FYI: in LMDE5 reboot works without sudo.
My LMDE5 installation requires sudo for terminal command reboot now.
And if you do reboot without now?
If you think the issue is solved, edit your original post and add the word solved to the title.
User avatar
senjoz
Level 5
Level 5
Posts: 901
Joined: Tue Jun 09, 2020 3:55 am
Location: Kamnik

Re: Terminal commands "shutdown now" and "reboot now"

Post by senjoz »

Interesting, terminal command reboot, without now, works without sudo. That is true for LM20.3, LMDE5 and Manjaro.
vimes666
Level 6
Level 6
Posts: 1241
Joined: Tue Jan 19, 2016 6:08 pm

Re: Terminal commands "shutdown now" and "reboot now"

Post by vimes666 »

I am more surprised that the now argument actually seems to do something as it is not mentioned in the manual:

Code: Select all

man reboot
If you think the issue is solved, edit your original post and add the word solved to the title.
rene
Level 20
Level 20
Posts: 12212
Joined: Sun Mar 27, 2016 6:58 pm

Re: Terminal commands "shutdown now" and "reboot now"

Post by rene »

The privilege stuff is a matter of...

As per

Code: Select all

$ ls -l $(which reboot shutdown)
lrwxrwxrwx 1 root root 14 feb  4 09:19 /usr/sbin/reboot -> /bin/systemctl
lrwxrwxrwx 1 root root 14 feb  4 09:19 /usr/sbin/shutdown -> /bin/systemctl
you find that the current reboot and shutdown are systemd implementations, and as such, authenticate via polkit. Specifically you in /usr/share/polkit-1/actions/org.freedesktop.login1.policy find for org.freedesktop.login1.power-off and org.freedesktop.login1.reboot as requested by shutdown and reboot:

Code: Select all

<defaults>
	<allow_any>auth_admin_keep</allow_any>
	<allow_inactive>auth_admin_keep</allow_inactive>
	<allow_active>yes</allow_active>
</defaults>
with then the "allow_active" part saying that both shutdown and reboot is allowed for clients in active sessions on local consoles. I.e., that same user that could hit the power or reboot button on the case anyway (and if you hot-glued those buttons feel free to change that policy with an override in /etc/polkit-1). The permission does not extend to e.g. someone logged in over ssh or in fact to a not physically logged in user.

I see that the "now" thing is only a matter of not being allowed to write the reboot parameter file:

Code: Select all

$ reboot now
Failed to write reboot parameter file: Permission denied
Yes, bit clumsy perhaps, but assuming that "reboot parameter file" is written to the root directory (haven't in fact a clue), yes, that needs not just org.freedesktop.login1.power-off/reboot. sudo doesn't have the ability to make the distinction between local or otherwise, and between active or otherwise, so can not act similarly -- but if it could've it would've.
vimes666
Level 6
Level 6
Posts: 1241
Joined: Tue Jan 19, 2016 6:08 pm

Re: Terminal commands "shutdown now" and "reboot now"

Post by vimes666 »

rene wrote: Wed Feb 08, 2023 1:18 pm ...
Yes, I see now that it says Failed to write reboot parameter file with any string you add to the command.
If you think the issue is solved, edit your original post and add the word solved to the title.
User avatar
LPH_[retired]
Level 2
Level 2
Posts: 80
Joined: Wed Dec 16, 2020 12:06 pm
Location: 3rd Rock
Contact:

Re: Terminal commands "shutdown now" and "reboot now"

Post by LPH_[retired] »

fyi

On Mint 20.3 here. I use

Code: Select all

shutdown -r 0
which reboots the machine immediately with out sudo.
For convenience I created an alias name restart. Works fine.

Must admit I'm not clear on the difference between shutdown -r and reboot command. Other than appearing to be doing the same thing, is there a difference?
Preferred one over the other?
(Apologies not trying to hijack this thread)
Alcohol is gods apology for making us self aware.
James May
rene
Level 20
Level 20
Posts: 12212
Joined: Sun Mar 27, 2016 6:58 pm

Re: Terminal commands "shutdown now" and "reboot now"

Post by rene »

LPH_[retired] wrote: Wed Feb 08, 2023 3:02 pm Must admit I'm not clear on the difference between shutdown -r and reboot command. Other than appearing to be doing the same thing, is there a difference? Preferred one over the other?
Other than shutdown needing/allowing for that timeout argument, no, also shutdown is on current Mint in fact systemctl, and shutdown -r 0 does other than a bit of parsing of said -r 0 and acting on it no other than reboot.

In times not long forgotten -- although I don't myself remember if it was still so in Mint 19 and/or Mint 20 -- shutdown in fact still came from util-linux whereas reboot was already the systemd one so back then there was a difference (even if not really any preferred one) but at least currently, it's all just systemctl:

Code: Select all

$ ls -l $(which shutdown halt reboot)
lrwxrwxrwx 1 root root 14 feb  4 09:19 /usr/sbin/halt -> /bin/systemctl
lrwxrwxrwx 1 root root 14 feb  4 09:19 /usr/sbin/reboot -> /bin/systemctl
lrwxrwxrwx 1 root root 14 feb  4 09:19 /usr/sbin/shutdown -> /bin/systemctl
User avatar
senjoz
Level 5
Level 5
Posts: 901
Joined: Tue Jun 09, 2020 3:55 am
Location: Kamnik

Re: Terminal commands "shutdown now" and "reboot now"

Post by senjoz »

Thank you, rene, for your detailed explanation. Obviously the argument now is not appropriate for the reboot command and sudo is only some kind of workaround for the wrong command.
Locked

Return to “Other topics”