MongoDB replicaSet error AuthenticationFailed (code 18)

Whenever I see replication error due to bad auth it’s because the keyfile is not the same on each server. The keyFile has to match on each of the replica set members exactly. I had this issue previously and this resolved the issue (I had a copy error).

I would double check the Keyfile and if you see they don’t match make sure they do and then restart any node you had to update it on and check again.

They keyfile is how they nodes authenticate to each other internally so seeing a bad auth on replication is the reason I suspect this could be an issue.

****I usuall use mongodb on VMs and I see this is in Docker but I would assume the same is true.

1 Like