Not --auth parameters mongodb service starts, the default connection without a user name and password. mongodb user database is established as a unit, each database has its own administrator. When you set up a user, you need to establish a database administrator in admin, administrator login after this, the equivalent of a super administrator. Involve server configuration aspects of the operation, we need to switch to the admin database.
1. Create a user
Create a user admin database:
use admin
db.addUser ( 'sa', '123456', false); username sa, 123456, not read-only for false. The default is true, the default is read-only.
User created. Here is start the service:
[Root @ localhost mongodb245] # ./bin/mongod -f mongodb.conf --auth service starts
[Root @ localhost mongodb245] # ./bin/mongo client connectivity services, although this time the connection service, but can not do anything, needs to be certified.
2, user authentication (login)
The following is the authentication command:
use admin
db.auth('sa','123456');
Since the admin user to add the library is a super administrator, so that the user can operate the other libraries.
After logging in with other libraries created for the sa user: use shop; db.addUser ( 'ushop', 'ushop123', false);
If you exit the client, re-use ushop logged on, the user can only operate shop ushop library, for example:
[root@localhost mongodb245]# ./bin/mongo
use shop;
db.auth('ushop','ushop123');
3, change the user password
You can modify the user login passwords of other libraries with library users admin, user login other libraries can also modify their own passwords. as follows:
use shop;
db.auth('ushop','ushop123');
db.changeUserPasswd ( 'ushop', '123456 '); new password to the user ushop 123456.
4, delete users
You can delete a user login other libraries with library users admin, user login other libraries can also delete their own. as follows:
use shop;
db.auth('ushop','ushop123');
db.removeUser ( 'ushop'); ushop user is deleted, it can no longer log in.
5, mongodb can specify a lot, very complex character, dba may be particularly detailed classification when you create a user, usually set to false or true this coarse-grained it.