mongodump from remote node - unable to authenticate using mechanism "SCRAM-SHA-256"
Asked Answered
G

6

13

Tried taking dump from a remote node and got the following 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.

Error Screenshot

Tried two methods to take dump from the remote node. But got the same error in both the methods.

# Method 1
mongodump -h remoteip@port -u xxx -p xxx --db xxx --authenticationDatabase admin

# Method 2
mongodump --uri "mongodb://username:password@remoteip:port/db?authSource=admin"

How to resolve this?

Gibberish answered 8/7, 2020 at 15:5 Comment(3)
Wrong credentials or wrong auth source or user does not exist, use server log to determine which it is.Bethanie
Hi, I have the same issue. I use the same connection string with MongoDB compass, but is failed with mongodump. How have you fix the issue ?Longspur
Maybe using the option --authenticationDatabase admin could resolve your issue.github.com/stefanprodan/mgob/issues/104Cloutman
C
13

I had the same issue. In my case, the password has special characters. It works with single quote for password:

-p 'my_password'
Chronaxie answered 19/10, 2020 at 9:47 Comment(0)
S
21

For me (trying to use mongodump on a single node DB on the same host), using --authenticationDatabase admin did the trick:

mongodump -u root --password 'secret' --authenticationDatabase admin -d mongo-dev -o /tmp/dump-2020-11-27.bson


(courtesy of mongodump from remote node - unable to authenticate using mechanism "SCRAM-SHA-256")

Spire answered 27/11, 2020 at 11:11 Comment(3)
I believe this is the correct answer. You need to specify the authSource with --authenticationDatabaseGladsome
--authenticationDatabase adminBadalona
Thank you for this answer! The error message is very confusing to debug. Do note that if you created a new db for the data entries while setting up mongo, you will need to use that. admin is the default.Deflection
C
13

I had the same issue. In my case, the password has special characters. It works with single quote for password:

-p 'my_password'
Chronaxie answered 19/10, 2020 at 9:47 Comment(0)
C
6

1.If you are using an URI for mongodump command,--authenticationDatabase admin option is equivalent to ?authSource=admin

mongodump --uri "mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]"

sample url:

mongodump --uri "mongodb+srv://username1:password1@host1/db1?authSource=admin" 
Camillecamilo answered 8/3, 2021 at 5:15 Comment(0)
K
3

I had the same problem and solved it using single quotes in the password like this:

   --password 'secret'
Kaliope answered 11/11, 2020 at 22:29 Comment(1)
Surprisingly this worked in a Spring Framework configuration fileMixup
S
0

Was in the same spot that you are, solved it this way:

mongodump --uri "mongodb+srv://username:password@yourmongodbclustersourceurl" --archive \
mongorestore --uri "mongodb+srv://username:password@yourmongodbclusterdestinationurl" --archive \
--nsExclude "admin.system.*"

Needless to mention, you just need to change your username, password and the url in this formula and voila. Good luck.

Skiff answered 20/11, 2020 at 19:26 Comment(0)
N
0

I had that problem and solved it by removing the special characters. For example, in my case I had a password abc@123. The connection string would be

mongodb://myuser:abc@[email protected]:27017/mydb?authSource=admin

as we can see a problem is generated because the "@" is a special character to separate the elements of the connection string , and I had to replace it with "%40", so my password was left as "abc%40123". And depending on the console that I used (powershell, command prompt, git bash, etc.) it generated the backup with an error or with a correct response. By removing the "@" everything worked correctly.

Possibly there is some way to configure this encryption, but in my case I preferred to change the password. I hope it will be useful to someone, greetings.

Nagano answered 31/5, 2023 at 19:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.