简体   繁体   English

在Ubuntu桌面中的mongoDb中启用身份验证

[英]Enable authentication in mongoDb in Ubuntu Desktop

I am usign Ubuntu 16.04 and trying to enable auth in mongodDb 我使用Ubuntu 16.04,并尝试在mongodDb中启用身份验证

I created a new User by 我创建了一个新用户

db.createUser({
user:"Sun",
pwd:"Sun",
roles:[{role:"userAdmin",db:"pet"}]
})

I checked the user by 我通过检查用户

db.getUsers();

But I am still able to modify database without providing username and password 但是我仍然能够在不提供用户名和密码的情况下修改数据库

I tried to enable authorizations by the commands provided in documentation but its not working for me. 我试图通过文档中提供的命令启用授权,但对我不起作用。

In my system to start the mongodb i have to write 在我的系统中启动mongodb我必须写

sudo service mongod start
mongod

Please tell me how to enable auth in mongoDb 请告诉我如何在mongoDb中启用身份验证

It sounds like you may be missing a config directive in your mongod.conf file. 听起来您mongod.conf文件中可能缺少配置指令。

check step 4 in the docs 检查文档中的步骤4

Re-start the MongoDB instance with access control. 使用访问控制重新启动MongoDB实例。

Re-start the mongod instance with the --auth command line option or, if using a configuration file, the security.authorization setting . 使用--auth命令行选项或( 如果使用配置文件)security.authorization设置重新启动mongod实例。

So in your config file you should have the line; 因此,在您的配置文件中,您应该有这行;

security.authorization: enabled

From a test box with CentOS the file is located at /etc/mongod.conf and should look something like this (Checking you paths are correct etc) 从带有CentOS的测试盒中,文件位于/etc/mongod.conf并且应如下所示(检查路径是否正确等)

systemLog:
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongod.log

storage:
  dbPath: /var/lib/mongo
  journal:
    enabled: true

processManagement:
  fork: true
  pidFilePath: /var/run/mongodb/mongod.pid

net:
  port: 27017
  bindIp: 0.0.0.0

security.authorization: enabled

You may also find it easier to use one of the management tools to manage you users with a GUI (presuming your on a Windows client) as its much easier then doing everything via the command line... 您可能还会发现使用其中一种管理工具通过GUI管理您的用户(假定您在Windows客户端上)更为容易,因为通过命令行完成所有操作要容易得多...

Once you have updated your config remember to restart your Mongod instance and check the log file at /var/log/mongodb/mongod.log to make sure there are no errors on startup. 更新配置后,请记住重新启动Mongod实例,并检查/var/log/mongodb/mongod.log的日志文件,以确保启动时没有错误。

Remember you need to give your users access to any given database, I assign my users to each database, and not via the 'admin' db - I find it easier. 记住,您需要授予用户访问任何给定数据库的权限,我将用户分配给每个数据库,而不是通过'admin'数据库分配-我觉得这更容易。

And lastly - If you find you have locked yourself out for some reason don't panic! 最后-如果您发现自己由于某种原因而被锁定, 请不要惊慌! just change the config line security.authorization: enabled to disabled and restart your instance you will the be able to log back in without any authentication! 只需将配置行security.authorization: enabled更改为disabled并重新启动实例,您将无需任何身份验证即可登录!

The log file will also give you pointers as to access problems so check that while your testing/setting up your users. 日志文件还将为您提供有关访问问题的指针,因此请在测试/设置用户时进行检查。

And remember once finished secure your deployment and check you can't login or do anything without a valid login. 并且请记住,一旦完成保护部署的安全,并检查您是否无法登录或在没有有效登录的情况下无法执行任何操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM