FeaturedHow-ToRaspberry Pi

How to SSH into Raspberry Pi: A Step-by-Step Guide

5 Mins read
Pi-oneer in Remote Access: SSH into Your Raspberry Pi

Secure Remote Access: The Complete Guide to SSH into Your Raspberry Pi in 2025

Secure Shell (SSH) is an essential tool for anyone working with a Raspberry Pi, providing encrypted remote access to your device from anywhere on your network. Whether you’re running your Pi as a headless server (without a monitor), managing multiple devices, or simply prefer the efficiency of command-line access, SSH offers a secure and convenient way to interact with your Raspberry Pi remotely.

In this comprehensive guide for 2025, we’ll walk through everything you need to know about setting up, securing, and troubleshooting SSH on your Raspberry Pi. By following these steps, you’ll be able to control your Pi from another computer without needing a dedicated display, keyboard, or mouse.

Understanding SSH

SSH (Secure Shell) is a network protocol that creates an encrypted connection between two devices, allowing for secure remote access. It follows a client-server model, where your Raspberry Pi runs an SSH server, and your computer uses an SSH client to connect to it.

The default SSH port is 22, though this can be changed for enhanced security (more on that later). All data transmitted via SSH is encrypted, protecting your commands and sensitive information from potential eavesdropping on your network.

Prerequisites

Before setting up SSH on your Raspberry Pi, ensure you have:

  • A Raspberry Pi with Raspberry Pi OS installed (formerly known as Raspbian)
  • A computer (Windows, macOS, or Linux) on the same local network
  • Network connectivity for both devices (Wi-Fi or Ethernet)
  • An SSH client installed on your computer:
    • Windows: PuTTY or Windows Terminal with OpenSSH
    • macOS/Linux: Terminal (OpenSSH is pre-installed)
  • The Raspberry Pi’s IP address or hostname (we’ll cover how to find this)

Enabling SSH on Raspberry Pi

SSH is disabled by default in Raspberry Pi OS for security reasons. Here are three methods to enable it:

Method 1: Using Raspberry Pi Imager (Recommended for Headless Setup)

The Raspberry Pi Imager tool now offers advanced options that allow you to configure SSH during the OS installation process:

  1. Download and install Raspberry Pi Imager on your computer
  2. Insert your microSD card into your computer
  3. Open Raspberry Pi Imager and select your preferred OS
  4. Click the gear icon (⚙️) to access advanced options
  5. Check “Enable SSH” and choose between “Use password authentication” or “Allow public-key authentication only”
  6. Set your username and password (highly recommended to change from default)
  7. Configure your Wi-Fi settings if needed
  8. Click “Save” and then “Write” to create your bootable SD card with SSH pre-enabled

Method 2: Using Raspberry Pi Configuration (With Monitor Setup)

If you already have your Raspberry Pi set up with a display:

  1. Open the Terminal on your Raspberry Pi
  2. Type sudo raspi-config and press Enter
  3. Navigate to “Interface Options” using the arrow keys
  4. Select “SSH” and press Enter
  5. Choose “Yes” to enable the SSH server
  6. Select “Finish” and reboot if prompted

Method 3: Command Line Method

If you already have terminal access to your Pi:

  1. Open the Terminal
  2. Run the following commands: sudo systemctl enable ssh sudo systemctl start ssh
  3. Verify SSH is running with: sudo systemctl status ssh

Method 4: Headless Setup with Empty File (Alternative Method)

If you’re setting up a Pi without a monitor and don’t have Raspberry Pi Imager:

  1. After writing Raspberry Pi OS to your SD card, reinsert it into your computer
  2. Create an empty file named ssh (no file extension) in the boot partition
  3. Safely eject the SD card and insert it into your Raspberry Pi
  4. Power on your Pi, and SSH will be enabled automatically

Finding Your Raspberry Pi’s IP Address

Before connecting via SSH, you need to know your Raspberry Pi’s IP address. Here are several methods:

Method 1: Using Terminal on Raspberry Pi (If You Have Display Access)

If you have direct access to your Pi:

hostname -I

Method 2: Check Your Router’s Connected Devices List

  1. Access your router’s admin interface (typically by entering 192.168.1.1 or 192.168.0.1 in a web browser)
  2. Log in with your router credentials
  3. Look for “Connected Devices” or “DHCP Clients List”
  4. Find your Raspberry Pi in the list (it might be labeled as “raspberrypi”)

Method 3: Network Scanning Tools

Use tools like nmap to scan your network:

nmap -sn 192.168.1.0/24

(Replace the IP range with your network’s range)

Method 4: Using mDNS/Avahi

If your Raspberry Pi has Avahi daemon installed (included by default in most Raspberry Pi OS versions):

On Linux or macOS:

ping raspberrypi.local

On another Linux machine with Avahi tools:

avahi-browse -t _ssh._tcp

Connecting to Your Raspberry Pi via SSH

From Linux or macOS

  1. Open Terminal
  2. Use the SSH command with your Pi’s username and IP address: ssh pi@192.168.1.100 (Replace with your Pi’s actual IP address) Alternatively, if mDNS is working, you can use the hostname: ssh pi@raspberrypi.local
  3. When prompted about the authenticity of the host, type yes
  4. Enter your password when prompted

From Windows

Using PuTTY:

  1. Download and install PuTTY
  2. Open PuTTY
  3. In the “Host Name” field, enter your Pi’s IP address
  4. Ensure the “Port” is set to 22 and “Connection type” is SSH
  5. Click “Open”
  6. When prompted about the host key, click “Accept”
  7. Log in with username pi and your password

Using Windows Terminal or PowerShell:

Recent Windows versions include OpenSSH client:

ssh pi@192.168.1.100

Initial Login and Security

The default username for Raspberry Pi OS is pi and the default password is raspberry. For security reasons, you should immediately change this password after your first login:

passwd

Follow the prompts to set a new, strong password.

Security Best Practices for SSH

1. Change the Default Password

As mentioned above, this is your first line of defense:

passwd

2. Use SSH Keys for Passwordless Authentication

SSH keys provide more security than passwords:

  1. On your computer, generate an SSH key pair: ssh-keygen -t ed25519 -C "your_email@example.com"
  2. Copy your public key to the Raspberry Pi: ssh-copy-id pi@192.168.1.100
  3. Test the key-based login: ssh pi@192.168.1.100

3. Disable Password Authentication (After Setting Up SSH Keys)

Once SSH keys are working:

  1. Edit the SSH configuration: sudo nano /etc/ssh/sshd_config
  2. Find and modify these lines: PasswordAuthentication no ChallengeResponseAuthentication no UsePAM no
  3. Save the file (Ctrl+O, then Enter) and exit (Ctrl+X)
  4. Restart the SSH service: sudo systemctl restart ssh

4. Change the Default SSH Port

Changing from the default port 22 can reduce automated attacks:

  1. Edit the SSH configuration: sudo nano /etc/ssh/sshd_config
  2. Find the line #Port 22 and change it to a number between 1024 and 65535: Port 2222
  3. Save and restart SSH: sudo systemctl restart ssh
  4. Remember to specify the port when connecting: ssh -p 2222 pi@192.168.1.100

5. Set Up a Firewall

Install and configure UFW (Uncomplicated Firewall):

sudo apt install ufw
sudo ufw allow 2222/tcp  # Replace with your SSH port
sudo ufw enable

6. Keep Your System Updated

Regularly update your Raspberry Pi OS:

sudo apt update
sudo apt full-upgrade

7. Limit SSH Access

Restrict which users can use SSH by editing /etc/ssh/sshd_config:

AllowUsers pi your_username

Troubleshooting Common SSH Issues

“Connection refused” Error

Possible causes and solutions:

  • SSH service is not running: sudo systemctl start ssh
  • Incorrect IP address: Double-check using methods above
  • Firewall blocking access: Check your firewall settings
  • Wrong port number: Verify you’re using the correct port

“Host key verification failed”

This happens when the SSH key of your Pi has changed:

ssh-keygen -R 192.168.1.100

Then try connecting again.

Authentication Issues

  • Verify you’re using the correct username and password
  • Check if your SSH keys are properly set up
  • Ensure the .ssh directory permissions are correct: chmod 700 ~/.ssh chmod 600 ~/.ssh/authorized_keys

Network Connectivity Problems

  • Verify both devices are on the same network
  • Try pinging your Raspberry Pi: ping 192.168.1.100
  • Check if your Pi has a valid IP address

Conclusion

SSH provides a powerful and secure way to remotely access your Raspberry Pi, enabling headless operation and efficient device management. By following this guide, you’ve learned how to enable SSH on your Pi, find its IP address, connect from various operating systems, and implement crucial security measures.

Remember that security should always be a priority – change default passwords, use SSH keys, and keep your system updated. With these practices in place, you can safely enjoy the convenience of remote access to your Raspberry Pi for all your projects.

Now that you’ve mastered SSH access, you’re ready to explore the full potential of headless Raspberry Pi setups for home automation, media servers, network tools, and countless other applications without needing a dedicated display.

Leave a Reply

Your email address will not be published. Required fields are marked *