Most Raspberry Pis are used for a dedicated purpose, for a specific tool.

The setup may well be headless, without a monitor, keyboard, or mouse.

To shut down these Pis, unplugging the power is not recommended.

Raspberry Pi with hand holding the power cable

It will result in a corrupted microSD card, sooner or later.

Headless Raspberry Pis need to be shut down remotely.

A few simple commands will accomplish the task.

Selecting Raspberry Pi Configuration from the Preferences menu

you could use SSH or VNC to shut down Pis remotely, depending on the OS.

VNC Server by RealVNC is already built into Raspberry Pi OS; you oughta enable it, though.

Navigate toMenu > Preferences > Raspberry Pi Configuration.

Enabling SSH and VNC in the Raspberry Pi Configuration tool

In theInterfacestab, toggle the VNC option to on and reboot the Pi.

VNC Server should start automatically at the next boot.

Shut Down Raspberry Pi Remotely Via SSH

Install SSH, andconnect to the Raspberry Pi using SSH.

The Raspberry Pi OS shutdown menu

By doing so, the Pi stays up-to-date with security patches.

get in to your router, find the port forwarding option, and set it up.

The internal and external ports are 22; the IP address is that of your Pi.

Entering the shutdown command in the Raspberry Pi terminal

Once done, you could connect to the Pi using its public IP address.

Then, issue theshutdowncommand, as you would do from your gear on a local data pipe.

One way to get around this is by using a high-capacity power bank as the power source.

Setting up SSH and VNC port forwarding in the router menu

Raspberry Pi consumes little power and so can run for a long time using a power bank.

The latter should automatically shut off when the power draw is less than 30mA.

So, after you grab shut down the Pi, the power bank will auto-shutoff.

Raspberry Pi powered by a power bank

However, you do need to double-check it shuts down correctly to avoid possible corruption of its SD card.

It’s also advisable to back up the data from the card, just in case.