Turning Off Your Raspberry Pi from Afar with a Few Easy Commands

Learn how to remotely shutdown your Raspberry Pi, even when you’re not physically near it. This article will guide you through the process using SSH and the command line interface. …


Updated October 6, 2023

Need help with your Raspberry Pi?
Contact Me!

Do you love silly Raspberry Pi Projects?
Check out my this YouTube Channel!


Learn how to remotely shutdown your Raspberry Pi, even when you’re not physically near it. This article will guide you through the process using SSH and the command line interface.

If you own a Raspberry Pi and work with it regularly, you know that sometimes it can be inconvenient to have to physically access your device in order to turn it off or restart it. Luckily, there are ways to remotely shutdown and reboot your Raspberry Pi using SSH (Secure Shell) and the command line interface. This article will show you how to do so.

Prerequisites:

  • A Raspberry Pi with an internet connection.
  • An SSH client installed on your local machine. If you’re on Windows, you can use PuTTY. For Mac or Linux users, you can use the built-in Terminal application.
  • Basic knowledge of using the command line interface (CLI).

Setting up Remote Access:

Before we get into shutting down your Raspberry Pi remotely, we need to make sure it’s set up for remote access over SSH. Follow these steps to enable SSH on your Raspberry Pi:

  1. Insert the microSD card with the Raspbian operating system into your computer and open the ssh file in the root directory of the drive. If there is no ssh file, create one using a text editor (e.g., Notepad on Windows or TextEdit on Mac). Save and eject the card.
  2. Plug the microSD card into your Raspberry Pi and power it on.
  3. Find your Raspberry Pi’s IP address by running hostname -I in the terminal (Linux) or cmd (Windows). Alternatively, you can check your router’s DHCP client list to find the device’s assigned IP address.
  4. Use your SSH client to connect to the Raspberry Pi using its IP address and the default username (pi) and password (raspberry). For example: ssh pi@192.168.0.100 (replace 192.168.0.100 with your Raspberry Pi’s IP).
  5. Once connected, run the following command to change the default password: passwd. Enter your current password, followed by a new password twice. This will help secure your Raspberry Pi if it is ever accessed remotely.

Shutting Down Your Raspberry Pi Remotely:

Now that you have set up remote access over SSH, you can shut down your Raspberry Pi using the following commands in the terminal (Linux) or command prompt (Windows):

  1. Connect to your Raspberry Pi using SSH by entering ssh pi@<your_pi's_IP> in the terminal/command prompt.
  2. Type sudo shutdown -h now and press Enter. This will immediately power off your Raspberry Pi.

If you want to restart your Raspberry Pi remotely, run: sudo reboot.

Conclusion:

Now you know how to remotely shutdown and restart your Raspberry Pi using SSH and the command line interface. This is a powerful tool that can save time and effort when working with your Raspberry Pi from afar. Just remember to always secure your device by changing the default password and keeping your network safe.