Connecting a Raspberry Pi 4 running Ubuntu Desktop 23.10 to a Mac via SSH often fails due to disabled services or network isolation. This guide resolves the issue by enabling the SSH server on the Pi, verifying network connectivity, and configuring macOS terminal settings for a stable connection.
Enable SSH on Ubuntu Desktop
Ubuntu Desktop does not enable the SSH daemon by default to save resources and improve security out of the box. You must explicitly activate this service before your Mac can establish a connection. First, access the Raspberry Pi directly using a monitor, keyboard, and mouse, or connect via a local Ethernet cable if Wi-Fi is unstable. Open the terminal application on the Pi. To ensure the SSH service starts automatically upon boot, run the following command:sudo systemctl enable ssh
Next, start the service immediately without waiting for a reboot:
sudo systemctl start ssh
Verify that the service is active and running by checking its status:
systemctl status ssh
You should see an "active (running)" message in green text. If the service is inactive, check for errors using journalctl -xeu ssh. Note that on some minimal installations, you may need to install the package first with sudo apt install openssh-server, though Ubuntu Desktop usually includes it pre-installed.
Identify the Raspberry Pi's IP Address
Your Mac needs the specific IPv4 address of the Raspberry Pi to initiate the connection. Since both devices are likely on the same local network, finding this address is straightforward. On the Raspberry Pi terminal, use theip command to display network interfaces:
ip addr show
Look for the interface connected to your network. If you are using Wi-Fi, look for wlan0; if using Ethernet, look for eth0. Under the relevant interface, find the line starting with inet. It will look something like inet 192.168.1.15. Record this IP address.
Alternatively, you can use the hostname if your router supports mDNS resolution. In many home networks, you can reach the Pi using raspberrypi.local. Test this from your Mac terminal by pinging the address:
ping raspberrypi.local
If the ping returns replies, you can use ssh [email protected] instead of the numeric IP. However, numeric IPs are more reliable if DNS resolution is inconsistent.
Configure macOS Terminal Settings
macOS comes with OpenSSH client pre-installed, but users often encounter issues related to the shell environment or key authentication. Before attempting the connection, ensure your Mac is ready. Open the Terminal app on your Mac. If you are using zsh as your default shell, which is standard on newer macOS versions, ensure your path is correctly configured. If you previously encountered issues with SSH commands not being found, refer to our guide on Fixing zsh: command not found: ssh -Y on Mac Terminal. To test basic connectivity, try connecting with verbose output to see where the handshake might fail:ssh -v [email protected]
Replace 192.168.1.15 with your Pi's actual IP address. The -v flag provides detailed logs. Look for lines indicating "Connection established" or "Authentications that can continue." If you see "Permission denied," the credentials are incorrect. If you see "No route to host," there is a network configuration issue.
Handle Authentication and User Permissions
Ubuntu Desktop typically creates a user namedubuntu during installation. Ensure you are using the correct username. If you created a different user during setup, replace ubuntu with your username in the SSH command.
When prompted for a password, enter the password associated with that user account. If you have set up SSH keys, ensure your private key is accessible. You can specify a key file using the -i flag:
ssh -i ~/.ssh/id_rsa [email protected]
If you frequently connect, add an entry to your ~/.ssh/config file on the Mac to simplify future connections:
Host pi
HostName 192.168.1.15
User ubuntu
IdentityFile ~/.ssh/id_rsa
After adding this, you can simply type ssh pi to connect.
Troubleshoot Network Isolation
If the connection times out, check your network settings. Some routers isolate devices on the same Wi-Fi network from communicating with each other, especially on guest networks. Ensure both your Mac and Raspberry Pi are on the same primary LAN segment. Additionally, verify that the firewall on the Raspberry Pi is not blocking port 22. While Ubuntu Desktop typically allows SSH through the default firewall, custom configurations might block it. Check the firewall status with:sudo ufw status
If UFW is active, allow SSH traffic with:
sudo ufw allow ssh
If you recently changed network settings or had previous SSH issues, consider reviewing our article on Fixing Incoming SSH Connection Issue on macOS: Temporary Solution - Reboot, as a simple reboot of either device can clear stale network states.
Frequently Asked Questions
Why does SSH work on Linux but not on my Mac?
The SSH protocol itself is identical across platforms, so the difference lies in client configuration or network policies. macOS may have stricter firewall rules or key permissions. Ensure your Mac's firewall allows outgoing connections and that your SSH key has correct read permissions (600).What if I forget the password for the ubuntu user?
If you cannot log in via SSH, you must reset the password physically. Boot the Raspberry Pi into recovery mode or use a live USB to mount the root filesystem and change the password using thepasswd command. Alternatively, re-flash the SD card if data loss is acceptable.
Can I use port forwarding to connect from outside my home?
Yes, but it requires configuring your router to forward external port 22 to the Raspberry Pi's internal IP on port 22. For security, consider using a non-standard external port and setting up key-based authentication only, disabling password login entirely.How do I know if the SSH server is actually listening?
Runnetstat -tlnp | grep :22 or ss -tlnp | grep :22 on the Raspberry Pi. If you see a line listing LISTEN on port 22, the server is active and ready to accept connections. If nothing appears, the service is not running.
Is it safe to leave SSH enabled on my Raspberry Pi?
It is safe if you use strong passwords or SSH keys and keep your system updated. However, exposing SSH to the internet without proper security measures makes it vulnerable to brute-force attacks. Always disable password authentication in/etc/ssh/sshd_config and use keys instead.