Enable and Use SSH on Raspberry Pi OS
Learn how to enable SSH on Raspberry Pi OS, find your Pi on the network, connect from Windows, macOS, or Linux, transfer files, and troubleshoot common SSH problems.
What SSH does
SSH, or Secure Shell, is an encrypted protocol for remote command-line access. It lets you administer a Raspberry Pi over a local network or another reachable network without connecting a monitor and keyboard to the Pi.
The SSH server runs on the Raspberry Pi. It is commonly provided by OpenSSH and includes the sshd server process. The SSH client runs on the computer you use to connect; examples include the ssh command, PuTTY, and graphical SFTP applications.
SSH encrypts login credentials and session traffic. Encryption does not make every setup safe automatically: use strong credentials, verify the server identity, keep software updated, and restrict which networks can reach the service.
For background on terminal use, see Terminal in Raspbian and Useful Terminal Commands.
Requirements
- A Raspberry Pi running Raspberry Pi OS or an older Raspbian release.
- A network connection for the Pi, using Ethernet or Wi-Fi.
- A client computer on the same local network for the basic setup.
- The Pi's hostname or IP address.
- A local user account and password, or a configured SSH key.
- An SSH client. OpenSSH is normally available on Linux, macOS, and modern Windows. PuTTY is a graphical alternative for Windows.
You should understand basic usernames, passwords, administrator privileges, and local networking before proceeding. See Connect to the Internet if the Pi is not yet online.
SSH service status and defaults
SSH availability and default behavior vary between older Raspbian releases and current Raspberry Pi OS releases. Do not assume that SSH is enabled or that an old default username and password exist. Verify the service and explicitly enable it when necessary.
The OpenSSH server service is named ssh. From a local terminal on the Pi, check it with:
sudo systemctl status sshA running service normally shows an active state. If you need to enable it and start it immediately, use:
sudo systemctl enable --now sshWays to enable SSH
| Method | When to use it | Main action | Notes |
|---|---|---|---|
raspi-config from a local terminal | The Pi has a display, keyboard, or an existing local shell | Open sudo raspi-config, choose the interface or service options, select SSH, and enable it | A reboot is usually unnecessary; the service can start immediately |
| Desktop Raspberry Pi Configuration application | A graphical Raspberry Pi OS desktop is available | Open Raspberry Pi Configuration and enable SSH in its interface or service settings | The exact menu wording can vary by release |
| Raspberry Pi Imager customization | Preparing a new installation before first boot | Use OS customization to enable SSH and configure the account and network | Preferred for most headless installations |
| Boot-partition marker file | A compatible headless setup workflow needs a simple SSH enablement marker | Place an empty file named ssh in the image's boot partition before booting | Also provision a user account; the boot partition filename or mount label can vary by image and operating system |
Enable SSH with raspi-config
- Open a terminal on the Raspberry Pi.
- Run the configuration utility:
sudo raspi-config- Open the interface or service options.
- Select the SSH option.
- Choose to enable the SSH server and confirm the choice.
- Exit the utility and verify the service:
sudo systemctl status sshSSH normally becomes available without a reboot. If it does not start automatically, run sudo systemctl enable --now ssh. More configuration utility guidance is available in Raspi Config.
Prepare a headless Pi before first boot
A headless Pi runs without a monitor or keyboard. The most reliable modern approach is to use Raspberry Pi Imager's OS customization settings before writing the storage card.
- Choose the Raspberry Pi OS image and storage device in Raspberry Pi Imager.
- Open the operating system customization settings.
- Set a hostname.
- Create a user account and choose a strong password.
- Enable SSH and select password authentication or public-key authentication.
- Configure Wi-Fi, locale, and wireless settings if Ethernet will not be used.
- Write the image, insert the storage device into the Pi, and boot it.
Current Raspberry Pi OS images require a user account to be created before first login. Do not rely on a universal legacy default username or password.
For compatible image workflows, you can request SSH enablement by mounting the image's boot volume on another computer and creating an empty file named ssh. Do not add a filename extension. The boot partition's filename or mount label may differ between images and operating systems. This marker enables the service, but it does not replace the required first-user setup. Raspberry Pi Imager customization is preferred because it can configure the hostname, account, password, Wi-Fi, locale, and SSH together.
Find the Raspberry Pi on the network
Use a hostname
A hostname is a network name assigned to a device. If the local network and client support mDNS (multicast DNS), the Pi may be reachable as:
<hostname>.localFor example, if the configured hostname is mypi, try mypi.local. mDNS support is common but not universal, so use the IP address if name resolution fails. You can learn more about changing the device name in Change Raspberry Pi's Hostname.
Display the address on the Pi
From a local Pi terminal, run:
hostname -IYou can also inspect all interfaces and addresses with:
ip addressCheck the router
Open the router's DHCP client or connected-device list and look for the Pi's hostname or hardware address. DHCP automatically assigns addresses, and an address can change after a lease expires or the Pi reconnects. For regular administration, consider a DHCP reservation in the router or a carefully configured static address.
Connect with OpenSSH
On Linux, macOS, or Windows with OpenSSH, use the configured username followed by the hostname or IP address:
ssh <username>@<hostname>.localssh <username>@<ip-address>If SSH has explicitly been configured on a nonstandard port, specify it with -p. The normal SSH port is TCP port 22:
ssh -p <port> <username>@<ip-address>At the first connection, the client displays the server's host-key fingerprint and asks whether to continue. A host key identifies the SSH server. Its fingerprint is a short representation used for verification. Accept the key only after confirming that the fingerprint belongs to the intended Pi, using a trusted local method where possible. Once accepted, the identity is saved in the client's known_hosts file.
Next, enter the Pi user's password, or let the client use the configured private key. A successful login opens a shell prompt. Confirm that the remote system is the Pi:
hostname && whoamiConnect with PuTTY on Windows
- Open PuTTY.
- Enter the Pi hostname or IP address in Host Name.
- Set Port to
22, unless you explicitly configured another port. - Select SSH as the connection type.
- Choose Open.
- Review the first-connection host-key prompt and verify the fingerprint before accepting it.
- Enter the Raspberry Pi username and password at the terminal prompts.
| Client platform/tool | Connection method | Example target format | Authentication options |
|---|---|---|---|
| Linux/macOS OpenSSH | ssh command | ssh user@pi.local | Password or private key |
| Windows OpenSSH | ssh command in a terminal | ssh user@192.168.1.50 | Password or private key |
| PuTTY on Windows | GUI session configured for SSH | Hostname or IP in Host Name, port 22 | Password or configured private key |
| SFTP/WinSCP for files | SFTP session over SSH | sftp user@pi.local | The same account, host, port, and key or password |
Basic remote administration
Commands typed in an SSH shell execute on the Raspberry Pi, not on the client computer. These safe checks show your identity, machine name, current directory, and files:
whoami
hostname
pwd
lssudo runs an administrative command with elevated privileges. Understand a command before using it, especially commands that delete files, modify networking, or change permissions. End the session with either command:
exitlogoutSSH security fundamentals
- Use a unique, strong password and do not retain known default credentials.
- For repeated access, prefer public-key authentication. The public key is installed on the Pi, while the private key remains on the client.
- Protect private keys with filesystem permissions and, where practical, a passphrase. Never share a private key.
- Generate an Ed25519 key pair on the client with:
ssh-keygen -t ed25519 -C "<client-label>"Install the public key for the Pi user in /home/<username>/.ssh/authorized_keys with secure ownership and permissions. Test a new key-based login in a separate terminal before changing any server settings.
Only after key login works should you consider disabling password authentication in the SSH server configuration. Keep a working recovery method available so you do not lock yourself out.
- Restrict SSH exposure to trusted local networks where possible.
- Beginners should avoid forwarding port 22 directly from the public internet to the Pi.
- Changing the SSH port can reduce automated scans, but it is not a replacement for strong authentication and access controls.
- Keep Raspberry Pi OS and OpenSSH updated. See Update Raspbian for update fundamentals.
Transfer files with SFTP
SFTP, the Secure File Transfer Protocol, transfers files through the SSH service. It uses the same hostname or IP address, username, port, and authentication method as SSH, but it provides file operations rather than an interactive remote shell.
Start a command-line SFTP session with:
sftp <username>@<hostname-or-ip-address>You can upload a file to the user's home directory, then use ls in the SSH session to verify it. The command-line scp tool and graphical clients such as WinSCP are other possibilities. See Use SFTP to Transfer Files.
Move from passwords to SSH keys
- Generate an Ed25519 key pair on the client.
- Install the public key in the Pi user's
authorized_keysfile. - Open a separate terminal and test a new SSH connection using the key.
- Confirm that key login works after a new session and, if possible, after reconnecting.
- Only then optionally disable password authentication.
Troubleshoot SSH connections
Start with physical and network checks: confirm that the Pi has power, its Ethernet or Wi-Fi connection is active, the client and Pi are on reachable networks, and the address belongs to the intended device. Check the router's DHCP list and try the IP address when hostname resolution is uncertain.
| Message or symptom | Likely cause | Checks and corrective action |
|---|---|---|
| Connection refused | SSH is disabled or stopped, the address belongs to another device, or a firewall rejects the connection | Confirm the address. Locally run sudo systemctl status ssh and sudo systemctl enable --now ssh. Check listening and firewall configuration. |
| Connection timed out | The Pi is offline, the address is wrong, networks are isolated, or a firewall silently drops traffic | Check power, network link, router clients, and whether both devices can reach each other. Try local-network access before remote access. |
| Could not resolve hostname | Incorrect hostname, unsupported or blocked mDNS, or the Pi has not joined the network | Try the router-assigned IP address, verify the hostname locally with hostname, and check mDNS and network support. |
| Permission denied | Wrong credentials, missing account, incorrect key, unauthorized public key, or disabled password authentication | Use the account created during imaging. Do not assume a legacy default account exists. Check key selection and authorized_keys, or use local console access to repair credentials. |
| Host key verification failed | The Pi was reinstalled or replaced, the address points to another device, or an interception may be occurring | Verify the device identity through a trusted local method and compare fingerprints. Only after confirmation remove the obsolete local record. |
After a legitimate reinstall, remove the old client-side host-key entry with:
ssh-keygen -R <hostname-or-ip-address>Do this only after confirming that the device really was reinstalled or replaced. A changed host key can be a warning that the address now belongs to a different device.
Headless login is unavailable
If a headless Pi boots but accepts no SSH connection, recheck that SSH was enabled during imaging or through the boot setup, that a user account was provisioned, and that Wi-Fi details are correct. Inspect the router's client list for an unexpected address. If necessary, connect a display and keyboard temporarily and inspect the network and ssh service locally.
Next steps
SSH is one form of remote access. For other options, see Access Raspbian Remotely, and review Display IP Address when locating the Pi. A DHCP reservation or static network configuration can make regular administration more predictable.