User can't connect from command line?

1,870 views
Skip to first unread message

Patrick Coleman

unread,
Apr 26, 2016, 11:12:55 AM4/26/16
to mongodb-user
Hi,

I have mongoldb 3.2.5 set up on Ubuntu 14.04. I have authentication turned on.

I can connect as admin user from the command line.

mongo admin -u admin -p password

I can also just connect to mongo and use db.auth to become admin like..

mongo

> use admin

switched to db admin

> db.auth("admin", "password")

1


I have created another user(pat) that I can authenticate as using the db.auth command when

connected to mongod


> use pat

switched to db pat

> db.auth("pat", "password")

1


but I can't connect from the command line like this..


mongo patsdb -u pat -p password


I get 

MongoDB shell version: 3.2.5

connecting to: pat

2016-04-26T10:53:49.714-0400 E QUERY    [thread1] Error: Authentication failed. :

DB.prototype._authOrThrow@src/mongo/shell/db.js:1441:20

@(auth):6:1

@(auth):1:2


exception: login failed


In the mongod.log file I get


2016-04-26T11:09:59.482-0400 I NETWORK  [initandlisten] connection accepted from 127.0.0.1:50510 #10 (1 connection now open)

2016-04-26T11:09:59.497-0400 I ACCESS   [conn10] SCRAM-SHA-1 authentication failed for pat on patsdb from client 127.0.0.1 ; AuthenticationFailed: SCRAM-SHA-1 authentication failed, storedKey mismatch

2016-04-26T11:09:59.498-0400 I NETWORK  [conn10] end connection 127.0.0.1:50510 (0 connections now open)


Does anyone know what's going on?


Thanks.


Pat.



Mike Grayson

unread,
Apr 27, 2016, 7:26:59 PM4/27/16
to mongodb-user
In your first example, you authenticated against a DB named pat, in your second example you authenticated against a DB named patsdb. If you change patsdb to pay on your second example, it should work.

Patrick Coleman

unread,
Apr 29, 2016, 12:07:03 PM4/29/16
to mongod...@googlegroups.com
Hi Mike, Thanks for that information. Some of that I typed from a different computer and so I made a mistake. Both places should be patsdb.

I did find out that the only way it won't work is if I provide the password on the command line. If I leave it off I'm asked for it and I then get into mongo. I can the use db.auth to authenticate.

Thanks.



--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.

For other MongoDB technical support options, see: https://docs.mongodb.org/manual/support/
---
You received this message because you are subscribed to a topic in the Google Groups "mongodb-user" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mongodb-user/FMqVcnkrxtU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mongodb-user...@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/c4955833-453e-4bb9-aa8f-eb4a9da9d9bb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Kevin Adistambha

unread,
May 3, 2016, 1:35:41 AM5/3/16
to mongodb-user

Hi Pat

I can connect as admin user from the command line.

mongo admin -u admin -p password

I can also just connect to mongo and use db.auth to become admin like..

mongo

> use admin
switched to db admin

> db.auth(“admin”, “password”)

You can also use the --authenticationDatabase <dbname> parameter to the mongo shell, e.g.:

mongo admin -u admin -p password --authenticationDatabase admin

I have created another user(pat) that I can authenticate … but I can’t connect from the command line like this..

mongo patsdb -u pat -p password

If you have created the user pat on the database patsdb, the mongo command line should be:

mongo patsdb -u pat -p password --authenticationDatabase patsdb

The command above instructs the mongo shell to connect to the patsdb database, as user pat, with password password, and using patsdb as the authentication database. Please see the Users page for more information regarding MongoDB authentication and the significance of the authentication database.

If you are still having issues with authentication, could you please provide the output of the db.getUsers() command on both admin and patsdb databases?

Best regards,
Kevin

Reply all
Reply to author
Forward
0 new messages