Unable to authenticate to MongoDb if attempting remotely

Whenever I run the following command inside the server this works:

mongosh  --authenticationDatabase admin --username admin --password password123

But on my PC, I try to connect to the same server with the following

mongosh --host [server ip] --port 27017 --authenticationDatabase admin --username admin --password password123

and this doesn’t work MongoServerError: Authentication failed, I’ve already checked my firewall and everything seems okay, port 27017 is open both udp and tcp, this has been bugging me out since yesterday, what could be causing this?

Hi @Saylent_N_A, welcome to the forums.

Server logging should also show any failure reasons, search/filter on "c":"ACCESS".

A user can be created to include extra authentication restrictions on the client ip address(es) and server ip address(es).

Use the db.getUser('username', {showAuthenticationRestrictions:true}).authenticationRestrictions command to list any.

// example
[ { clientSource: [ '', '' ] } ]

Another possibility us that the port is being forwarded to another mongodb instance?


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