Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 297 Vote(s) - 3.47 Average
  • 1
  • 2
  • 3
  • 4
  • 5
command line authentication of mongo fails

#1
I am running mongo 2.2.2 on osx.

When I do the following authentication is going fine:

$ mongo
>> use admin
>> db.auth("uname", "password")

log:

Thu Mar 7 13:51:08 [initandlisten] connection accepted from 127.0.0.1:63474 #10 (4 connections now open)
Thu Mar 7 13:51:08 [conn10] authenticate db: admin { authenticate: 1, nonce: "123", user: "uname", key: "456" }

However when I try to authenticate directly from the commandline:

$ mongo admin -u uname -p password

I get the following error:

Thu Mar 7 14:25:52 [initandlisten] connection accepted from 127.0.0.1:63939 #12 (5 connections now open)
Thu Mar 7 14:25:52 [conn12] authenticate db: admin { authenticate: 1, nonce: "789", user: "uname", key: "147" }
Thu Mar 7 14:25:52 [conn12] auth: key mismatch uname, ns:admin
Thu Mar 7 14:25:52 [conn12] end connection 127.0.0.1:63939 (4 connections now open)

Does anyone know what causes this?
Reply

#2
A password containing special characters, especially the dollar sign, has to be put in single quotes to protect them from the command shell:


$ mongo admin -u uname -p 'password'

Reply

#3
**This is the way to access an authenticate MongoDB database from terminal**

mongo -u user_name -p "your_password" host_name/database_name

**Ex:**

mongo -u hasib -p "123456" localhost/my_db

Reply

#4
To Login to MongoDB Via Command Line do the following

$ mongo admin -u 'username' -p 'Password'
Reply

#5
You have to use the `--authenticationDatabase` to indicate mongodb where to find the user you have created. For example:

mongo admin -u uname -p 'password' --authenticationDatabase admin
Reply

#6
You could also connect using the mongo connection URL as follow:


mongo "mongodb://<user>:<password>@<host: 127.0.0.1>:<port: 27017>/<db_name>?authSource=admin"

- The db_name is optional.
- The host is usually 127.0.0.1 if you are
connection to localhost.
- The port is usually 27017.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through