2012-09-09(Sun)
MongoDBでユーザー認証してみる
MongoDBでユーザーを作成してみる。
ユーザーを作成
ユーザーを消す
mongo.confを設定
MongoDBを再起動
参考:
Security and Authentication
ユーザーを作成
> use pharaoh
switched to db pharaoh
> db.addUser('hogeuser', 'hogepass')
{ "n" : 0, "connectionId" : 2, "err" : null, "ok" : 1 }
{
"user" : "hogeuser",
"readOnly" : false,
"pwd" : "b212177e897528fb334f5e6a022d6105",
"_id" : ObjectId("50382c3666db9c3120642bd7")
}
> db.system.users.find() # 確認
{ "_id" : ObjectId("50382c3666db9c3120642bd7"), "user" : "hogeuser", "readOnly" : false, "pwd" : "b212177e897528fb334f5e6a022d6105" }
readOnlyユーザーにする場合は第三引数にtrueを付加する。
> db.addUser('hogeuser', 'hogepass', true)
ユーザーを消す
> db.removeUser( 'hogeuser' )
mongo.confを設定
$ vim /usr/local/mongo/bin/mongo.conf
# Turn on/off security. Off is currently the default
noauth = false
auth = true
-> 認証をtrueにする。
MongoDBを再起動
$ /etc/init.d/mongod restart
参考:
Security and Authentication
- 関連記事
-
- MongoDBでmongoimportとmongoexportを使ってみる
- MongoDBでユーザー認証してみる
- mongoの起動方法
スポンサーサイト