Raspberry Pi

How to Shut Down Raspberry Pi via SSH

The Raspberry Pi doesn’t have any shutdown button to power off the device, and most users don’t bother to power it off correctly. This will create a severe issue for their Raspberry Pi devices if they continuously plug out the power cable to shut down the devices.

Since some users feel more comfortable working on their Raspberry Pi device terminal through SSH and don’t require any desktop setup to complete their tasks, they must have some information about how to shut down their Raspberry Pi devices via SSH to protect their devices from any mishap. This article is a detailed guide to properly shutting down Raspberry Pi through SSH.

How to Shutdown Raspberry Pi via SSH

There are several ways to shut down your Raspberry Pi via SSH; however, before discussing them, let’s find out how you can enable the SSH service on your Raspberry Pi device.

Enable SSH on Raspberry Pi

You can enable the SSH service on your Raspberry Pi device from the Raspberry Pi configuration. You can open the configuration either from the main menu or through the terminal command.

To open the Raspberry Pi configuration through the desktop, go to the main menu and click on the “Raspberry Pi Configuration” in the “Preferences” section.

Enable the SSH service from the “Interfaces” tab.

If you want to enable SSH from the terminal, you can do so by opening the Raspberry Pi configuration in the terminal through the following command:

$ sudo raspi-config

Head towards the “Interfaces Options” and select SSH service to enable it.

Access Raspberry Pi Terminal Through SSH

After successfully enabling the SSH service on Raspberry Pi, it’s now time to access the Raspberry Pi terminal through SSH and for this reason, you will need to follow the below-mentioned steps:

Step 1: Open Command Prompt on your Windows system by running it as an administrator:

Step 2: Now, enter the following command in the Command Prompt:

$ ssh <RaspberryPI_username>@<IP Address>

If you don’t know your Raspberry Pi IP address, you can find it by executing the command “hostname -I” in the terminal.

Enter your Raspberry Pi password to complete the process of accessing the Raspberry Pi terminal through SSH.

Shutdown Raspberry Pi via SSH

After accessing the Raspberry Pi terminal, you are now ready to execute several commands to shutdown Raspberry Pi via SSH. There are three commands which are mostly used to shut down Raspberry Pi and you can apply those commands to shut down your device via SSH.

1: Halt Command

One of the simplest and most used commands to shut down the Raspberry Pi is the “halt” command, as it’s enough for you to shut down your device without any wait:

$ sudo halt

2: Power Off Command

You can also use the “power off” command to successfully shut down your Raspberry Pi device via SSH, which is given below:

$ sudo poweroff

3: Shutdown Command

This command seems to be more promising to shut down your Raspberry Pi, as you will find many options to shut down the Raspberry Pi device via SSH.

The following command will shut down the device as soon as you enter the command:

$ sudo shutdown now

If you apply only “shutdown”, it will stop the device in 1 minute and notify you about the shutdown timing.

In case you want to schedule timing for shutting down Raspberry Pi, you can do so by applying the following command:

$ sudo shutdown <Time>

In case you want to cancel the shut down at the given period, you can do so by executing the following command:

$ sudo shutdown -c

Conclusion

Shutting down your Raspberry Pi through SSH is helpful, especially when you are accessing your Raspberry Pi terminal from a Windows system. There are multiple ways through which you can safely shut down your Raspberry Pi device through SSH. If you want to shut down your device without any delay, you can use the commands like ”halt”, “poweroff” and “shutdown”. You can also set a timer with the “shutdown” command to schedule a shutdown at a given time.

About the author

Awais Khan

I'm an Engineer and an academic researcher by profession. My interest for Raspberry Pi, embedded systems and blogging has brought me here to share my knowledge with others.