0

So, as the title states, I cannot SSH to a Raspberry Pi from my Mac. I have done so in the past, but can't figure out why it won't work now.

Unless stated otherwise, all devices I mention below are hardwired to the same network.

This problem has come up a couple of times over the years, but it was always related to the known_hosts file on the Mac--I could delete the Pi's entry out of that file and then it would work again.

I get the dreaded Port 22: Connection Refused error. After scouring forms and trying many of the suggestions, I have had no luck. None of the problems really are the same as mine (I think all of them have been about setting up new Pi's or the Mac being the outright new variable on the network), but I thought I'd go about their troubleshooting. It seems that this is a catch-all error that has many solutions, but many more problems...

The Pi has Port 22 open and is listening to it. I can connect to it via other methods.

I can get around the problem:

  • I can SSH to a different Raspberry Pi on the network and then SSH to the Pi in question.
  • I can SSH to the Pi in question through Power Shell on a Windows computer I have.
  • I can SSH to the Pi through a terminal program on an iPhone and an iPad.
  • I can SSH to the Pi remotely from other devices outside of my network via port forwarding I have set up on my router.
  • I can Ping the Pi from the Mac
  • I can VNC to the Pi from the Mac.
  • I can SSH to the Pi in question from another device (the Pi's on my network are all headless) and then SSH to the Mac.
  • And, if I'm a little bored, I can SSH from my Mac to the other Pi, SSH to school, SSH to a family member's computer in another state, and then finally SSH back to the Pi that my Mac can't connect to.

So this has been going on for a long time now and the absurdity of the work arounds finally hit me. I am tired of the work around.

Any ideas what is happening? Why is the connection being refused between only these two devices?

12
  • 1
    are you using an IP address or a host name in the ssh command? anything interesting if you do ssh -vvv ....? Jun 20 at 2:01
  • Here's a search that may help
    – Seamus
    Jun 20 at 4:26
  • 1
    The big problem here is "connection refused" means the IP address is valid but the port is closed. That the IP address is valid does not mean it is the Raspberry Pi, so the two possibilities here are: 1) It is the wrong IP address, or 2) sshd is not running on the pi, or is using an alternate port. There's not much information beyond that anyone can offer, unfortunately.
    – goldilocks
    Jun 20 at 15:31
  • @Jaromanda X -- thank you for the reply. I am using an IP address when I connect to this Pi. This is what I get when I run that command OpenSSH_8.1p1, LibreSSL 2.7.3 debug1: Reading configuration data /etc/ssh/ssh_config debug1: /etc/ssh/ssh_config line 47: Applying options for * debug2: resolve_addr: could not resolve name .... as address: nodename nor servname provided, or not known debug1: resolve_canonicalize: hostname .... is an unrecognised address debug1: Connecting to .... port 22. ssh: Could not resolve hostname ....: -65540 Jun 21 at 4:37
  • @Jaromanda X -- That is kind of confusing to me that the hostname is unrecognized. It is an IP address that I can connect to in several different other ways... Jun 21 at 4:49
0

You have provided minimal information, so no one can definitively say.

I use .ssh/config StrictHostKeyChecking to avoid one of the Mac's foibles.

Host 10.1.*.*
   StrictHostKeyChecking no
   UseKeychain yes
   BatchMode yes
3
  • thank you for the replay. I tried adding this file. I was unable to connect to anything after this. Removing the file made everything work again, except the Pi in question. Jun 21 at 5:06
  • If you blindly used this file without entering the subnet you actually use (often 192.168.*.*) it will restrict to this subnet. See man ssh_config
    – Milliways
    Jun 21 at 5:14
  • I use the 192.168 subnet. I had changed it. I cannot connect to any devices on my network through ssh with that config file in the .ssh directory. Jun 22 at 23:03
0

Something that I tried to establish in my initial post was that I could connect to the Pi in just about any manner with other devices, just not my Mac.

Suggestions like sshd not running on the Pi or the IP address being incorrect just didn't make sense to me. If these were true, then I wouldn't be able to connect at all with any other device, right?

There was one other instance where this inability to connect occurred as well--if I ssh to the PI from my iPhone while on the 5Ghz Wifi, I could not connect with the same "Connection Refused" error. But, if I was on the 2.4Ghz Wifi, I could connect.

I was pretty sure that the Mac and iPhone were being blocked somehow.

I traced the blocks to some rules in iptables. I was able to confirm that the Mac's IP address and the iPhone's IP address (while on 5Ghz Wifi) were being blocked, whereas everything else on my network was open.

I am not sure how they ended up blocked, but the solution was to remove those rules and everything works again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.