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.
To stop a Raspberry Pi from the terminal (locally or remotely via SSH), type the command “sudo shutdown -h now”. All services will be stopped properly and immediately, the current session will be terminated and the Raspberry Pi will be powered off.
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 (via SSH)
In this first part, I explain the prerequisites to remotely access your Raspberry Pi via SSH. You can skip this if you are already connected, but it’s mandatory if you intend 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:
- 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 even Microsoft Windows now includes an SSH client in the command prompt, you can use the same command whatever your operating system.
- Open a terminal (or the command prompt on Windows)
- Type the following command:
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.
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.
To properly shut down a Raspberry Pi remotely, the only way is to use SSH and type one of the commands available to stop all services and turn the Raspberry Pi off. One of them is “sudo halt”, and it stops the Pi right away.
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 :
Probably the one to remember as it’s the shortest one:
There are a few options available, but that are not really useful in our case. So, the simple command like this should be enough.
It’s an alias of halt, you can use it if you prefer, but it’s basically the same one:
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
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
- Stop the Raspberry Pi in one minute
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.
Once the green light stops blinking, you can safely disconnect or turn off the power supply. The Raspberry Pi will start again as soon as you turn the power supply back on (as with most computers, it’s not possible to do this remotely).
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.
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:
- 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.
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.
How to reboot the Raspberry Pi via SSH?
To restart the Raspberry Pi via SSH, type the command “sudo reboot” in the terminal. It will properly stop all services and turn the Raspberry Pi off, but it will restart it automatically after that.
Can you remotely turn on a Raspberry Pi?
It’s not possible to remotely turn on a Raspberry Pi that is completely powered off, as it lacks the feature known as “Wake-on-Lan” (WoL) which is commonly found in more standard computers and laptops.
This feature allows a device to be woken up from a powered down or sleep state through a network message, but doesn’t exist for Raspberry Pi devices.
It’s important to keep in mind that a Raspberry Pi is a low-power device, so leaving it running continuously does not consume a significant amount of power.
However, if power usage, heat, or long-term wear and tear are concerns, a smart plug may be the best solution.
Whenever you’re ready, here are other ways I can help you:
The RaspberryTips Community: If you want to hang out with me and other Raspberry Pi fans, you can join the community. I share exclusive tutorials and behind-the-scenes content there. Premium members can also visit the website without ads.
Master your Raspberry Pi in 30 days: 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.
The Raspberry Pi Bootcamp: Understand everything about the Raspberry Pi, stop searching for help all the time, and finally enjoy completing your projects.
Master Python on Raspberry Pi: Create, understand, and improve any Python script for your Raspberry Pi. Learn the essentials step-by-step without losing time understanding useless concepts.
You can also find all my recommendations for tools and hardware on this page.