Can’t connect to Raspberry Pi via MacOS laptop. Works via other devices including Linux and iOS.

This is the macOS terminal command and output:

ssh -vvvvvv -p 9091 [email protected]
OpenSSH_8.8p1, OpenSSL 1.1.1m  14 Dec 2021
debug1: Reading configuration data /usr/local/etc/ssh/ssh_config
debug2: resolve_canonicalize: hostname is address
debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts' -> '/Users/discord/.ssh/known_hosts'
debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts2' -> '/Users/discord/.ssh/known_hosts2'
debug3: ssh_connect_direct: entering
debug1: Connecting to [] port 9091.
debug3: set_sock_tos: set socket 3 IP_TOS 0x48
debug1: connect to address port 9091: Bad file descriptor
ssh: connect to host port 9091: Bad file descriptor

From the pi I see

error: kex_exchange_identification: Connection closed by remote host
Connection closed by port 63461 

1 Answer 1


The debug log indicates that the TCP connection fails for some reason even before any SSH specific data is sent over the TCP connection. You can try to to disable the connection time out using the command ssh -vvvvvv -o ConnectTimeout=0 -p 9091 [email protected]. If this does not work try to use WireShark to analyze why the TCP connect from the MAC to the PI fails.

To check whether you can establish a TCP connection from the MAC to the PI you can try telnet 9091 If successful you will see something like:

bash> telnet 9091
Connected to
Escape character is '^]'.
  • If I recall correctly I get a Bad file descriptor from telnet. I'll try this again when I'm at the machine to verify.
    – discord
    Feb 7, 2022 at 17:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .