How do I enable SSH on Raspberry Pi?

Enabling SSH (Secure Shell) on a Raspberry Pi allows you to remotely access your device over the network, making it convenient to manage without a direct keyboard or monitor connection. Here's how to enable SSH on your Raspberry Pi:

Using Raspberry Pi OS Desktop

If you're using the Raspberry Pi OS desktop interface, you can enable SSH via the configuration settings:

  1. Open the Raspberry Pi Configuration tool by navigating to the Raspberry Pi icon in the top-left corner, then Preferences, and finally Raspberry Pi Configuration.
  2. In the Raspberry Pi Configuration dialog, click on the Interfaces tab.
  3. Find the SSH option and click Enable.
  4. Click OK to apply the changes. You might need to reboot your Raspberry Pi for the changes to take effect.

Using raspi-config on the Command Line

If you're operating your Raspberry Pi in headless mode (without a graphical interface) or you prefer using the command line, follow these steps:

  1. Open a terminal on the Raspberry Pi or connect to it via SSH if it's already enabled.
  2. Type sudo raspi-config and press Enter. This opens the Raspberry Pi Software Configuration Tool.
  3. Navigate to Interfacing Options using the arrow keys and press Enter.
  4. Scroll down to SSH and press Enter.
  5. Select Yes to enable the SSH server.
  6. Select Ok when prompted with the confirmation message.
  7. Finish and exit raspi-config by selecting Finish. You may choose to reboot your Raspberry Pi to ensure all settings are correctly applied.

Enabling SSH Without a Screen (Headless Setup)

If you don't have your Raspberry Pi connected to a monitor or keyboard, you can enable SSH by creating a file in the boot directory:

  1. Access the boot partition of your Raspberry Pi's SD card on another computer. This partition should be accessible when you insert the SD card into your computer's card reader.
  2. Create an empty file named ssh (without any extension) in the root of the boot partition.
  3. Safely eject the SD card from your computer and insert it back into your Raspberry Pi.
  4. Power on your Raspberry Pi. SSH will be enabled automatically.

Connecting to Your Raspberry Pi via SSH

Once SSH is enabled, you can connect to your Raspberry Pi from another computer using an SSH client. You'll need to know the Raspberry Pi's IP address on your network.

On a computer on the same network, open a terminal (Linux or macOS) or an SSH client like PuTTY (Windows) and connect using the following command:

ssh pi@<IP_ADDRESS>

Replace <IP_ADDRESS> with your Raspberry Pi's IP address. The default username is pi, and the default password is raspberry (you should change this password for security reasons).

This should give you command-line access to your Raspberry Pi, from which you can manage it remotely.