If you’re able to ping your Raspberry Pi but cannot SSH or telnet into it, here are a few potential reasons and solutions:
1. SSH Service Might Not Be Running
- Check if SSH is installed and running:
- Connect to your Pi directly (using a keyboard and monitor).
- Run:
sudo systemctl status ssh
- If it’s inactive, start it:
sudo systemctl start ssh
- If it’s not installed, install it:
sudo apt update sudo apt install openssh-server
2. Firewall or iptables Configuration
- The firewall on the Raspberry Pi may be blocking SSH.
- Check iptables rules:
sudo iptables -L
- You can flush the rules temporarily for testing:
sudo iptables -F
- Check iptables rules:
3. SSH Port Configuration
- Ensure SSH is listening on the default port (22) and not another port.
- Check SSH config file:
sudo nano /etc/ssh/sshd_config
- Look for the line:
Port 22
- If a different port is specified, make sure you’re using that port when connecting (e.g.,
ssh pi@192.168.0.101 -p <port>
).
- Check SSH config file:
4. Network Issues
- Ensure there is no network-level filtering or restrictions, like router settings or VLAN rules, that block SSH connections.
5. Device-Specific Issues
- If this issue persists after ensuring SSH is running and properly configured, try rebooting the Raspberry Pi:
sudo reboot
6. Misconfigured SSH Client
- Clear the SSH client’s known hosts (sometimes the keys change, and this causes a connection error):
ssh-keygen -R 192.168.0.101
7. SSH Login Issues
- Check for user permissions or disabled password authentication in the
sshd_config
file, ensuringPermitRootLogin
orPasswordAuthentication
is appropriately set.
When you manually set the Raspberry Pi to a fixed IP address that was previously assigned by DHCP, the SSH client may have been trying to use the old key from the previous dynamic IP.
By changing the IP address and using ssh-keygen -R to remove the old entry in the known hosts file, you likely cleared any conflicting SSH keys, allowing the connection to succeed again.
This can happen because the SSH client stores the server’s public key in ~/.ssh/known_hosts, and if the IP address changes but the key doesn’t match, the client refuses to connect.