Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what's the easiest way to password protect mongodb database for remote user?

Tags:

mongodb

I have a mongodb running in my server, for local connections to the db I don't need any password to protect it(that is within the same physical machine, meaning connect to the server thru the 127.0.0.1 ip address).

But I don't want other people in the network be able connect to my database without password, only the authorized user. So I want to do password protection for the remote user.

How to do it?

like image 554
Bin Chen Avatar asked Jul 11 '12 00:07

Bin Chen


People also ask

How do I create a username and password for MongoDB?

So to create an administrative user first we use the admin database. In this database, we create an admin user using the createUser() method. In this method, we set the user name is “hello_admin”, password is “hello123” and the roles of the admin user are readWrite, config, clusterAdmin.


2 Answers

Right now monogdb does not support authentication mode based on the user location. So that means if you run mongod with --auth that will apply to everyone.

There are no (yet) advanced authentication schemas like IP, protocol source, etc. For now you can only define if the user has read only or write permissions on a database. So basically the only thing mongodb cares is if you typed the right password for the right user.

Personally in all production environment I would recommend to use the secure mode, because even if you allow only connection from a localhost any users who has access to the local server or any malicious script on the host can easily wipe all your data.

like image 199
golja Avatar answered Oct 21 '22 13:10

golja


The MongoDB Security and Authentication page has information on configuring user authentication and firewall settings.

Note that when you enable password authentication for a database, the authentication requirement will apply to both local and remote users (so you will also need to connect with a password through the local IP).

like image 45
Stennie Avatar answered Oct 21 '22 12:10

Stennie