Passing MongoDB user password in newline for Mongodump command using bash script - mongodb

I am trying to backup a MongoDB instance that has authentication enabled but i get this error:
$> mongodump --username=admin --password=******* --authenticationDatabase=admin --db=ixpay --collection=blacklist --out=.
2020-06-02T21:39:39.086+0000 Failed: can't create session: could not connect to server: connection() : auth error: sasl conversation error: unable to authenticate using mechanism "SCRAM-SHA-256": (AuthenticationFailed) Authentication failed.
I am attempting this data dump using a bash script but i noticed that if i run the command directly on my terminal without the --password flag it works but then Mongodump shell will prompt for password like so:
$ mongodump --username=admin --authenticationDatabase=admin --db=ixpay --collection=blacklist --out=.
Enter password:
How do i write the mongodump command in bash, so that i can interactively(but quietly) pass the password to the Mongodump command when i execute the script?

Related

Windows Batch Script for Automated Mongodb Backup

I have setup a superuser in mongodb and I am able to do a backup manually in the command line or connect to the database with the username and password in the console or in Compass, but if I move that command to a batch script and run the script, I always get the error:
Failed: can't create session: could not connect to server: connection() : auth error: sasl conversation error: unable to authenticate using mechanism "SCRAM-SHA-256": (AuthenticationFailed) Authentication failed.
The command is:
mongodump --username myusername --password mypassword --out C:\backups --db mydb --authenticationDatabase admin
I have updated the bindIp to 0.0.0.0 and added security: authorization: "enabled".
Any thoughts on why I can't run this in the batch script. I am using Mongo 4.2
Thanks

Why do I get "FATAL: Ident authentication failed for user" when trying to log into my postgres DB?

If I type psql directly in my command prompt, I am logged into postgres as the user myusernamexy with all rights I need.
However, I want to connect to the database with this command:
psql -h localhost -p 5432 -U myusernamexy mydatabasexy
When I type the above command into the command prompt, I get this error
FATAL: Ident authentication failed for user "myusernamexy "
Why do I get this error and what do I need to change in the command to make it work?

Authentication failed when using mongo to connect mlab.com

I have a account on mlab.com.
mlab-hosted deployment is running MongoDB 3.0.
I install MongoDB 3.0.10 in my computer.
I connect to mlab.com using this command:
mongo ds019480.mlab.com:<port>/<database> -u <username> -p <password>
But I get error message:
MongoDB shell version: 3.0.10-4-gbd56c2f
connecting to: ds019480.mlab.com:19480/larry-database
2016-04-08T08:45:27.101+0800 E QUERY Error: 18 Authentication failed.
at DB._authOrThrow (src/mongo/shell/db.js:1271:32)
at (auth):6:8
at (auth):7:2 at src/mongo/shell/db.js:1271
exception: login failed
How do I connect to mlab.com successfully?
remove any signs/symbols from your password. in particular '!' and '$'.
Aside from the common mistake of using your Heroku or mLabs username/password, another one may be using "double quotes".
mongo ds012345.mlab.com:<port>/<database> -u "username" -p "password"
exception: login failed
mongo ds012345.mlab.com:<port>/<database> -u 'username' -p 'password'
rs-ds012345:PRIMARY>
What’s the Difference Between Single and Double Quotes in the Bash Shell?
Conclusion: All characters within single quotes are interpreted as a string character.

s3cmd pipe mongodb 3.0.2 SASL auth failed

Does anybody experience an issue with s3cmd and mongoimport after having upgraded to mongodb 3.0.2? I am receiving the SCRAM-SHA1 / SASL error but have no clue how I can fix this? The connection from and to s3 is still unaffected and working properly.
I was untill recently successfully using s3cmd to pipe the output from mongodb 2.6:
s3cmd get s3://filename - | mongoimport -d testdb -c testcollection
which is now returning:
"Failed: error connecting to db server: server returned error on SASL
authentication step: Authentication failed."
Thanks in advance
Try using the --authenticationDatabase parameter to direct the mongoimport tool to the database that holds the user’s credentials. Currently it fails to authenticate since it can't find the location of those credentials.
The full command should look something like this:
s3cmd get s3://filename - | mongoimport -d testdb -c testcollection -u <user_name> -p <password> --authenticationDatabase admin
This is all true to version 2.4 and up of the mongoimport tool, so make sure you have an updated version.

MongoDB shell command line authentication fails

I set up replica set with authentication. I used this tutorial. I set up keyfile, admin user and other users. It all works fine - anonymous access is disabled and I can login
$ mongo
MongoDB shell version: 2.6.1
connecting to: test
Error while trying to show server startup warnings: not authorized on admin to execute command { getLog: "startupWarnings" }
rs0:PRIMARY> use admin
switched to db admin
rs0:PRIMARY> db.auth("USERNAME","PASSWORD")
1
rs0:PRIMARY>
using credentials of users I created.
But I can't login from command line
$ mongo -u 'USERNAME' -p 'PASSWORD'
MongoDB shell version: 2.6.1
connecting to: test
2014-05-18T14:23:47.324+0200 Error: 18 { ok: 0.0, errmsg: "auth failed", code: 18 } at src/mongo/shell/db.js:1210
exception: login failed
using the same credentials. I haven't find anything helpful in the documentation or here on SO.
The in-shell authentication performed in your example is against the admin database. The command line posted above does not specify a database and is therefore authenticating against the default database which is test. Try this instead to authenticate via command line against the admin db:
mongo admin -u 'USERNAME' -p 'PASSWORD'
if the server is not on the local host then you can use this:
mongo your_host_name:your_port/admin -u 'USERNAME' -p 'PASSWORD'
Perhaps different now because of an update since this question was originally answered, but authentication only succeeds when wrapping username/password in double quotes.
e.g.,
mongo admin -u "myName" -p "myPassword"