Anyone new to the wonderful world of Raspberry Pi may find that some common processes are difficult to execute. Safe shutdowns are no different.
You can use the command sudo halt now to immediately turn off your Pi and disconnect from your current session.
But how can you shut down remotely? We have put together this quick guide to get you remotely shutting down your Pi like a pro.
Before we begin, you need to be aware that this process is done via SSH.
SSH or Secure Shell is a type of network communication protocol that allows two computers to communicate or share data. It creates a secure and encrypted connection between these two computers, even though they are connected via an unsecured network.
New to SSH? There are some prerequisites to remotely shutting down your Pi.
There are some protocols and settings that you need to put in place before you can remotely shut down your Pi. You need to:
Have SSH enabled
Know your Pi’s IP address
Connection to your Pi
We will go through each of these in turn.
Firstly, you need to make sure that you have SSH enabled. This is not the default setting for Raspberry Pi, so you need to do it manually.
To do this on the Raspberry Pi desktop:
Open the main menu and select preferences
Start the Raspberry Pi Configuration tool.
Go to the Interfaces tab and click on Enable on the second line. This will enable SSH.
Click OK to apply these changes. Now SSH will automatically be turned on every time you boot until you go back and change it again.
Not using the desktop? Try using Raspberry Pi OS Lite. We think that this method is the easiest way to enable SSH.
Use the command sudo raspi-config to open up the Configuration Tool
Now go to Interface Options
Find SSH from the list of options
Follow the prompt. You will be asked if you want to enable the SSH server. You need to click yes.
As with the desktop method, the SSH server will now be automatically turned on each time you boot up your Pi until you go back and change this setting.
IP Address of Your Pi
Next up is finding out your Pi’s IP address.
Via the Pi OS desktop, this is simple. All you need to do is hover your mouse above the network icon which is at the top right-hand corner of the screen. Your IP address should appear, and you can make a note of it.
Getting your IP address on Raspberry Pi OS Lite is also simple. Use the command ifconfig and your IP address should appear on the second line. You want the address after inet.
To avoid confusion, your IP address will be a series of numbers that are formatted as four 8-bit fields, separated by periods. Each of these numbers can vary from 0 to 255, so we can guarantee that your IP address will be somewhere between 0.0.0.0 and 255.255.255.255.
Connect to Your Pi
Now all this is sorted, you can connect to your Pi via SSH.
Keep in mind that Windows includes an SSH client, so you can use the same command whatever your Pi’s operating system.
Open a terminal or use the command prompt on Windows
Enter this command: ssh [email protected]_ADDRESS. Replace IP_ADDRESS with your Pi’s IP address that you retrieved in the last steps.
On the first connection, you may find that you need to accept the Pi’s ‘fingerprint.’ Do this by typing yes and then hitting Enter
If prompted, enter the password. The default is raspberry
You should now be connected to your Pi. Congratulations!
From here, you can remotely shut down your Pi.
Raspberry Pi Shutdown
As we have already discussed in different articles, improper Pi shutdown can be disastrous. It is easy to corrupt your data or to lose data – processes do not save and shut down correctly when an incorrect shutdown occurs, so you lose every change since the last save.
There are three methods to correctly and safely shut down your Pi.
You can use the halt command. This is the shortest command, so it is the most popular – it is easy to remember and quick to execute!
Use the command: sudo halt to execute a shutdown.
The poweroff command is very similar to the halt command. It is quick and simple and provides the same function.
Use the command: sudo poweroff to shutdown.
The shutdown command is perhaps the most interesting as there are different variations you can try.
Use the command: sudo shutdown now to shutdown your Pi immediately.
Use the command: sudo shutdown 18:12 to shutdown at a specific time. In this example, your Pi will be shut down at 12 minutes past 6 in the evening. You could also use a number to execute shutdown in the specified number of minutes.
If you use one of the last options, it may be of benefit to know how to cancel the shutdown – you don’t want it to turn off when you’re in the middle of something!
The command for canceling a scheduled shutdown is: sudo shutdown -c
Keep in mind that you will need to have administrator privileges to execute a shutdown or to cancel it. Be sure to put the ‘sudo’ command at the beginning if you are not logged in as a root user.
Keep in mind that only the administrator can log in after you have scheduled a shutdown. Any user who does not have administrator privileges will have the message ‘system is going down. Unprivileged users are not permitted to log in anymore.’
Setting a timer with the sudo shutdown command is technically a remote shutdown. Sort of!
Keep reading to find out how to automate shutdown from your computer.
We recommend that Windows users install Putty onto their computer to remotely shut down their Pi. Putty is a free SSH client that simplifies this process.
Once Putty has been installed, you need to create two new files.
In the stop-pi.bat file, you need to input this line: putty.exe -ssh [email protected]<IP> -pw <PASSWORD> -m stop.txt
Remember that you need to put your Pi’s IP address instead of IP, and you need to use your Pi’s password for the bit that says PASSWORD otherwise this will not work.
In the stop-cmd.txt file, you need to input: sudo shutdown now
You now need to save these files and then double-click on the stop-pi.bat. If you have done this correctly, your Pi should now be shut down remotely. You can close the windows that your computer has opened.
You can use these files to create a shutdown shortcut for your Pi. This can be a great time saver if you do a lot of Raspberry Pi-based work.
macOS or Linux
The process is very similar for Mac or Linux systems. The only difference is that you need to create a bash script and generate an SSH key that can be accessed without a password.
When you have this established, you can enter the following command into a new bash script: ssh [email protected]<IP> “sudo shutdown now”
Remember that you will need to type out your Pi’s IP address for the IP section. You can use this method on Windows too, but we find that using Putty is far easier!
Once you have completed the above steps, your Pi should now be shut down. Shut down remotely at that!
Disappointingly there is no way to remotely power your Pi back on. This means that you will need to unplug the power supply and then plug it back in. You can also try pressing the power button on your Pi case twice, but this method doesn’t always work.
You can remotely shut down your Pi once you know that you have SSH enabled, your Pi’s IP address and that your computer is connected to your Pi.
Once you have satisfied these prerequisites you can go ahead and begin to execute shutdown commands. Remember that there are several methods to do this, and you can even set a shutdown for a specific time or for a specified number of minutes.
If you want a true remote shutdown, your methodology will differ depending on your computer’s operating system. Keep in mind that Windows can also work using Mac’s instructions for the remote shutdown, but it is far easier to install Putty.