How to Safely Shut Down or Reboot a Raspberry Pi


To avoid data corruption or SD card damage, you should never just unplug the power from a Raspberry Pi. Instead, use one of these safe methods:
1. Shut Down via Command Line (SSH/Terminal)
A. Immediate Shutdown
bash
sudo shutdown -h now
-h
= Halt (completely powers off the system).After this, it’s safe to unplug the power.
B. Scheduled Shutdown (e.g., in 5 minutes)
bash
sudo shutdown -h +5 # Shuts down in 5 minutes
- Cancel with
sudo shutdown -c
.
2. Reboot the Raspberry Pi
bash
sudo reboot
or
bash
sudo shutdown -r now # -r = Reboot
3. Using the Desktop GUI (Raspberry Pi OS)
Click the Menu (top-left corner).
Select Shutdown.
Choose Shutdown or Reboot.
4. Hardware Power Button (If Configured)
Some cases have a physical power button connected to GPIO pins.
- Requires a shutdown script (Python or
systemd
service).
5. Emergency: If the System Freezes
If the Raspberry Pi is unresponsive:
Ctrl + Alt + Del (if a keyboard is connected).
If nothing works:
- Cut power (last resort—may corrupt the SD card!).
Important Notes
✅ Always shut down properly before unplugging—otherwise, SD card corruption may occur.
✅ For headless setups (no monitor), use ssh
to run shutdown
or reboot
.
✅ For auto-shutdown (e.g., during power loss), use a UPS (Battery Backup) or a shutdown script.
Quick Command Summary
Command | Action |
sudo shutdown -h now | Shut down immediately |
sudo shutdown -r now | Reboot immediately |
sudo reboot | Alternative reboot command |
sudo shutdown -h +10 | Shut down in 10 minutes |
Pro Tip: For automated shutdowns, use cron
or systemd
timers!
Subscribe to my newsletter
Read articles from ampheo directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
