如何把用户名和放大器;密码在MongoDB中? [英] How to put username & password in MongoDB?
问题描述
我想设置的用户名和放大器;密码为我的MongoDB。因此,任何远程访问将询问用户名和放大器;密码。有没有办法做到这一点?我试图从mongodb的网站教程并没有以下内容:
使用管理
db.addUser('theadmin','12345');
db.auth('theadmin','12345');
在这之后,我退出,然后再次运行蒙戈。而且我也不需要密码才能访问它。即使我连接到远程的MongoDB,我不会提示输入用户名和放大器;密码。
谢谢..我现在知道了。
这里是我的文档:
1)在蒙戈命令行:(让说,设置管理员)
>使用管理;
> db.addUser('管理','123456');
2)关闭服务器并退出
> db.shutdownServer();
>出口
3)重新启动的mongod与--auth
$ sudo的./mongodb/bin/mongod --auth --dbpath到/ mnt / DB /
4)运行蒙戈又在2种方式:
i)跑蒙戈先请登录。
$ ./mongodb/bin/mongo本地主机:27017
>使用admin
> db.auth('管理','123456');
ii)跑&安培;登录在命令行蒙戈。
$ ./mongodb/bin/mongo本地主机:27017 /管理-u管理-P 123456*用户名和放大器;密码将工作同样为mongodump和mongoexport。
您需要与建立用户后--auth选项来启动mongod的。
从MongoDB的网站:
运行数据库(mongod的过程)与--auth选项来启用安全性。必须具有将用户添加到管理员分贝--auth启动服务器之前,还是从本地主机界面添加的第一个用户。
<一个href=\"http://www.mongodb.org/display/DOCS/Security+and+Authentication\">http://www.mongodb.org/display/DOCS/Security+and+Authentication
I want to set up the user name & password for my mongoDB. so that any remote access will ask for the user name & password. Is there a way to do it? I tried the tutorial from the mongodb site and did following:
use admin
db.addUser('theadmin', '12345');
db.auth('theadmin','12345');
After that, I exit and run mongo again. And I don't need password to access it. Even I connect to the mongodb remotely, I am not prompted for user name & password.
Thanks.. I got it now. Here is what I document:
1) In mongo command line: (let say, set administrator)
> use admin;
> db.addUser('admin','123456');
2) Shutdown Server and exit
> db.shutdownServer();
> exit
3) Restart Mongod with --auth
$ sudo ./mongodb/bin/mongod --auth --dbpath /mnt/db/
4) Run mongo again in 2 ways:
i) run mongo first then login.
$ ./mongodb/bin/mongo localhost:27017
> use admin
> db.auth('admin','123456');
ii) run & login to mongo in command line.
$ ./mongodb/bin/mongo localhost:27017/admin -u admin-p 123456
* The username & password will work the same for mongodump and mongoexport.
You need to start mongod with the --auth option after setting up the user.
From the MongoDB Site: Run the database (mongod process) with the --auth option to enable security. You must either have added a user to the admin db before starting the server with --auth, or add the first user from the localhost interface.
http://www.mongodb.org/display/DOCS/Security+and+Authentication
这篇关于如何把用户名和放大器;密码在MongoDB中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!