Compass Error creating SSH Tunnel: EADDRINUSE

Hey, I am unable to connect to my mongodb through SSH. I mostly get EADDRINUSE. I would be happy to at least understand the error – what does it mean?

Error creating SSH Tunnel: connect EADDRINUSE <ip>:22 - Local (

I just tried the same setup with Studio3T/Robo3T (alternative GUI client) and the connection is working on the first try.

Sometimes in Compass, without any changes, I even get AUTHENTICATION FAILED. Does that mean mongodb auth or ssh auth? Sometimes, the SSH Port field is highlighted red, sometimes not. So weird.

Any ideas why Compass refuses to connect? I’d prefer using the official software but it just doesn’t seem to work. I have zero idea where to start debugging, what my configuration is missing, or if there are good and free alternatives to Compass. Help?

I tried with a rsa and a ppk file. I saw one post about the identify file being malformed – What kind of identify file is Compass really expecting here?

I have the latest Compass Version (1.23.0).
I tried from two different computers and two different networks.

Thank you for reading.

If you’re connecting to localhost use if you need an ip for the Hostname field.
You probably don’t have MongoDB configured to listen on the external interface.
I think basically you have set up more than you need to for localhost.

I should’ve made it clear that I try to connect to a remote server. On that server mongodb does not accept external interfaces, true. So hostname is my remote server that I ssh into, and then try to connect to its localhost.

I do this daily, doing it now.

Did you redirect the ports properly using ssh -L flag, e.g, something like:

ssh -L 27017:localhost:27017 me@myhost

(assuming you don’t have mongod running on the local machine, in which case you would need to use another port, e.g., 27117, on the right side of the -L argument and add the port number to your mongodb uri)?

Also if you name the interface (localhost) to ssh -L as I did above, that’s the interface, i.e.,, not the ethernet interface address of your computer.

1 Like

Hey Jack, thank you, that is super interesting. I completely skip the “More Options” and SSH Login of Compass now and do the following:

  • in my local terminal ssh -L 27017:localhost:27017 me@myhost
  • Create a new connection inside Compass to localhost with User/Pass Auth of the remote DB
  • Connect – it works :smile:

That’s a great solution, I didn’t know something like this was possible. I still don’t really understand why it doesn’t work with the SSH Options inside Compass, but this looks like a super future proof solution. Thanks!

1 Like

Ha! you got me, @thusman … I’m not much of a tool-using animal :slight_smile: I always use the lowest-level approach. SSH is “closer to ground” so I set up any necessary redirections there and then use whatever tool without it having to know about things. Wasn’t even aware Compass handles port redirections in any fashion.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.