How to Shut Down Raspberry Pi via SSH? (And a Bonus Tip)

1. To shut down your Raspberry Pi via SSH, you can use the command “sudo shutdown -h now”. This will immediately shut down the Raspberry Pi.

2. Bonus Tip: To reboot your Raspberry Pi via SSH, you can use the command “sudo reboot”. This will restart the Raspberry Pi.

When you start on Raspberry Pi, even simple actions like shutting down your device might be an issue, especially when using it remotely.
I will answer this question right away, and then give you more tips if you are interested.

A Raspberry Pi can be shut down from SSH using this command:
sudo halt
The device will stop after that, immediately disconnecting the current SSH session.

If you are not familiar with SSH or the command line, I will guide you step-by-step on how to this.
Also, if you need to do this regularly from your computer, don’t miss my tip on how to do this more efficiently.

By the way, if you are new to Raspberry Pi and want a step-by-step guide on how to do anything with it, feel free to check my e-book “Master your Raspberry Pi in 30 days”. It’s a 30-day challenge in which you’ll learn one new skill each day by practicing along the way. You’ll save time, money and start to enjoy any new project you want to try.

Connect to your Raspberry Pi (SSH)

In this first part, I will explain the things you need to access your Raspberry Pi via SSH. You can skip this if you are already connected, but it’s a prerequisite if you want to stop your Raspberry Pi remotely ?

Make sure SSH is enabled

Before anything else, make sure the SSH service is running.
By default, it’s not the case on Raspberry Pi OS, so you need to enable it.
Here is how to do this.

I’m giving you the short version here, but if you are new to this, I would recommend reading this other article first: Use SSH To Remote Control Your Raspberry Pi: A complete guide.

Raspberry Pi OS Desktop

If you have a desktop version, you can enable SSH like this:

  • Open the main menu, and go to Preferences
  • Start the Raspberry Pi Configuration tool
  • In the “Interfaces” tab, click on “Enable” or turn the slider on for the corresponding line (“SSH”)

Click OK to apply the changes.
From now, the SSH service will be started automatically on boot.

Raspberry Pi OS Lite

On Raspberry Pi OS Lite, the easiest way is to use raspi-config to do this:

  • Use the following command:
    sudo raspi-config
  • Go to Interface Options
  • Then SSH
  • And answer yes to the question “Would you like the SSH server to be enabled?”

The SSH server will start directly, and be enabled on boot, so you don’t have to do this each time.

Find your Raspberry Pi IP Address

Before connecting to your Raspberry Pi remotely, you’ll also need the IP address.

On Raspberry Pi OS Desktop, you can get it easily by hovering your mouse over the network icon in the top-right corner.

On Raspberry Pi OS Lite, you can use this command:
ifconfig
The IP Address is on the second line, after the “inet” keyword.
ifconfig

If you need further assistance for this step, I have a dedicated tutorial on the topic here.

Connect to the Raspberry Pi

Once the Raspberry Pi configured, you can now access it via SSH.
As Windows now includes an SSH client, you can use the same command whatever your operating system.

  • Open a terminal (or the command prompt on Windows)
  • Type the following command:
    ssh USER@IP_ADDRESS
    Replace IP_ADDRESS with the one you got in the previous step, and USER with the current user (it was “pi” on old installations, it’s now a custom one you create on the first boot).
  • On the first connection, you might need to accept the Raspberry Pi fingerprint, type “yes” and press Enter.
  • Then enter the user’s password.
    (It was “raspberry” by default previously, it’s now a custom one created by you).
    If you don’t remember it, check this article to recover your password.

That’s it, you are now connected to your Raspberry Pi.
You can follow the next part to stop it from there.

Are you a bit lost in the Linux command line? Check this article first for the most important commands to remember, and a free downloadable cheat sheet so you can have the commands at your fingertips.

Want to chat with other Raspberry Pi enthusiasts? Join the community, share your current projects and ask for help directly in the forums.

Shut down your Raspberry Pi via SSH

Pulling out the power supply, or using the power button of the case, is not the right way to stop a Raspberry Pi. It may corrupt the SD card depending on the processes in progress.

In this part, I will give you three commands to properly shut down the Raspberry Pi, and also a few tips to go further.

The 3 commands you can use to stop a Raspberry Pi

Without further ado, here are the three commands you can use to stop a Raspberry Pi :

  • Halt
    Probably the one to remember as it’s the shortest one:
    sudo halt
    There are a few options available, but that are not really useful in our case. So, the simple command like this should be enough.
  • Poweroff
    It’s an alias of halt, you can use it if you prefer, but it’s basically the same one:
    sudo poweroff
  • Shutdown
    This one is more interesting as there are several useful options available.
    The basic command to stop your Raspberry Pi will be:
    sudo shutdown now
    Options you may want to try:
    • Stop the Raspberry Pi in one minute
      sudo shutdown
      Other users will be notified.
    • Schedule the Raspberry Pi shutdown at a specified time
      sudo shutdown 06:00
      You can also use a cron for more options
    • Cancel scheduled shutdown
      sudo shutdown -c

In all cases, you need the administrator privileges to stop the system, so don’t forget to put the sudo command at the beginning if you aren’t already logged as root.

Also, once a shutdown is scheduled, non-administrators can’t log in anymore, they will get an error message:
System is going down. Unprivileged users are not permitted to log in anymore.

Create a script to automate this from your computer

In theory, you should be doing this every time you use your Raspberry Pi.
In some cases, it’s not the most convenient way. If your Pi is embedded, you might not want to connect to SSH each time just to stop it.
No problem, you can “automate” this.

On Windows

For Windows users, the easiest way is to use Putty in command line:

  • Install Putty if you don’t have it yet.
    It’s a free SSH client, you can download it here.
  • Create two new files:
    stop-pi.bat
    stop-cmd.txt
  • In stop-pi.bat, paste the following line:
    putty.exe -ssh pi@<IP> -pw <PASSWORD> -m stop.txt
    Don’t forget to put the IP address and password corresponding to the Raspberry Pi you want to stop.
  • And in stop-cmd.txt:
    sudo shutdown now
  • Save everything and double-click on stop-rpi.bat
    It should shut down your Raspberry Pi directly. You can close the windows opened by the script on your computer.

Not bad, you can now create a shortcut somewhere if you want, and use this each time you want to stop your Raspberry Pi.

On Linux / macOS

On Linux / macOS, it’s almost the same thing, but you’ll need to create a bash script.
Firstly, make sure to generate an SSH key and that you can access your Pi without typing any password.
Then paste this line in a new bash script:
ssh pi@<IP> "sudo shutdown now"

You can also use SSH keys on Windows, but it’s a bit more complicated, so Putty is the easiest way.

Turn the Raspberry Pi back on

Unfortunately, there is no way to power the Raspberry Pi back on remotely after this. So, the only thing you need to do is to unplug the power supply and plug it back in.

If there is a power button on your case (like on the Argon ONE I tested here), using it twice should work.

Additional Resources

Not sure where to start?
Understand everything about the Raspberry Pi, stop searching for help all the time, and finally enjoy completing your projects.
Watch the Raspberry Pi Bootcamp course now.

Master your Raspberry Pi in 30 days
Don’t want the basic stuff only? If you are looking for the best tips to become an expert on Raspberry Pi, this book is for you. Learn useful Linux skills and practice multiple projects with step-by-step guides.
Download the e-book.

VIP Community
If you just want to hang out with me and other Raspberry Pi fans, you can also join the community. I share exclusive tutorials and behind-the-scenes content there. Premium members can also visit the website without ads.
More details here.

Need help building something with Python?
Create, understand, and improve any Python script for your Raspberry Pi.
Learn the essentials step-by-step without losing time understanding useless concepts.
Get the e-book now.

You can also find all my recommendations for tools and hardware on this page.

How to Shut Down Raspberry Pi via SSH? (And a Bonus Tip)

Shutting down your Raspberry Pi via SSH is a great way to save time and energy. It’s also a great way to keep your Raspberry Pi running smoothly and efficiently. In this article, we’ll show you how to shut down your Raspberry Pi via SSH, as well as provide a bonus tip to help you get the most out of your Raspberry Pi.

Step 1: Connect to Your Raspberry Pi via SSH

The first step in shutting down your Raspberry Pi via SSH is to connect to it. To do this, you’ll need to have an SSH client installed on your computer. Once you have an SSH client installed, you can connect to your Raspberry Pi by entering the following command into your terminal:

ssh [email protected]

Once you’ve entered the command, you’ll be prompted to enter your Raspberry Pi’s password. Once you’ve entered the password, you’ll be connected to your Raspberry Pi.

Step 2: Shut Down Your Raspberry Pi

Once you’re connected to your Raspberry Pi, you can shut it down by entering the following command into your terminal:

sudo shutdown -h now

This command will shut down your Raspberry Pi immediately. Once the Raspberry Pi has shut down, you can disconnect your SSH connection by entering the following command into your terminal:

exit

Bonus Tip: Use a Script to Automate the Shutdown Process

If you want to make the shutdown process even easier, you can create a script that will automatically shut down your Raspberry Pi. To do this, you’ll need to create a file called “shutdown.sh” in your Raspberry Pi’s home directory. Once you’ve created the file, you can add the following code to it:

#!/bin/bash
sudo shutdown -h now

Once you’ve added the code to the file, you can make the file executable by entering the following command into your terminal:

chmod +x shutdown.sh

Now, whenever you want to shut down your Raspberry Pi, you can simply enter the following command into your terminal:

./shutdown.sh

This command will execute the script and shut down your Raspberry Pi. This is a great way to save time and energy when shutting down your Raspberry Pi.

Conclusion

Shutting down your Raspberry Pi via SSH is a great way to save time and energy. In this article, we’ve shown you how to shut down your Raspberry Pi via SSH, as well as provided a bonus tip to help you get the most out of your Raspberry Pi. We hope this article has been helpful and that you now have a better understanding of how to shut down your Raspberry Pi via SSH.

Jaspreet Singh Ghuman

Jaspreet Singh Ghuman

Jassweb.com/

Passionate Professional Blogger, Freelancer, WordPress Enthusiast, Digital Marketer, Web Developer, Server Operator, Networking Expert. Empowering online presence with diverse skills.

jassweb logo

Jassweb always keeps its services up-to-date with the latest trends in the market, providing its customers all over the world with high-end and easily extensible internet, intranet, and extranet products.

Contact
San Vito Al Tagliamento 33078
Pordenone Italy
Item added to cart.
0 items - 0.00
Open chat
Scan the code
Hello 👋
Can we help you?