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

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.

Raspberry Pi OS Desktop

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

Get My Commands Cheat Sheet!
Grab your free PDF file with all the commands you need to know on Raspberry Pi!
  • Open the main menu, and go to Preferences
  • Start the Raspberry Pi Configuration tool
  • In the “Interfaces” tab, click on “Enable” on the second 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:
The IP Address is on the second line, after the “inet” keyword.

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 pi@IP_ADDRESS
    Replace IP_ADDRESS with the one you got in the previous step
  • On the first connection, you might need to accept the Raspberry Pi fingerprint, type “yes” and press Enter.
  • Then enter the password (default: raspberry)

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

Get My Commands Cheat Sheet!
Grab your free PDF file with all the commands you need to know on Raspberry Pi!
Get My Commands Cheat Sheet!
Grab your free PDF file with all the commands you need to know on Raspberry Pi!

Reminder: Remember that all the members of my community get access to this website without ads, exclusive courses and much more. You can become part of this community for as little as $5 per month & get all the benefits immediately.

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:

Help me help them <3
Help me raise funds for education by donating to my Pencils of Promise campaign.
Together we could fund a school for them!
  • Install Putty if you don’t have it yet.
    It’s a free SSH client.
  • Create two new files:
  • 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, using it twice should work.

Get My Commands Cheat Sheet!
Grab your free PDF file with all the commands you need to know on Raspberry Pi!

Unlock the secrets of your Raspberry Pi

As you can see, even the things that seem pretty basic at first glance might take a long time when you are new to Raspberry Pi and Linux. So, trying bigger projects might be frustrating.

My goal on this website is to help you as much as possible, and if you need a boost in your learning, make sure to check my Raspberry Pi boot camp.
It’s a course for anyone who is just starting or want to start, to quickly overcome the first questions and have fun along the way.

Patrick Fromaget

I'm the lead author and owner of My goal is to help you with your Raspberry Pi problems using detailed guides and tutorials. In real life, I'm a Linux system administrator with a web developer experience.

Recent Posts