Mongo "auth failed" Only for Remote Connections. Local Works fine

Ahmed Haque picture Ahmed Haque · Jun 27, 2015 · Viewed 9.9k times · Source

I have a Bitnami MEAN instance running on EC2. After much finagling, I've been able to successfully connect to the DB using the local shell. I created authenticated users with all of the permissions necessary to access the data, and when I run the below code -- I am able to access the DB with no problem.

sudo mongo admin -u <USERNAME-p <PASSWORD>

That said, when I try to repeat this using a remote connection I am repeatedly given an "auth failed" error from MongoDB.

mongo <HOST>:<PORT>/<DATABASE> -u <USERNAME> -p <PASSWORD>

...

This is strange because I am using the exact same credentials as I do in running the local shell. The only difference is I'm including the host and port information. I've since also confirmed that my remote connection DOES work if I disable the auth parameter in mongodb.config.

mongo <HOST>:<PORT>/<DATABASE>

Obviously, in production I want to be able to authenticate. Do any of you have suggestions as to why there is a discrepancy between remote and local authentication?

Answer

Alexandre picture Alexandre · Jul 22, 2015

I was facing the same issue.

The problem for me:

My local mongo shell was v2.6.10. It uses an authentication method called MONGODB-CR that has been deprecated.

My server version is v3.0.4. It uses an authentication method called SCRAM-SHA-1.

Try to check your local shell and remote server versions with:

mongo --version
mongod --version

If they are different, upgrade your local shell to v3. (I had to uninstall and install it again.)