Setting read/write permissions on Mongodb folder

mongodb directory permission
unable to create/open lock file: /data/db/mongod lock windows
how to setup mongodb
mongodb read only directory data/db
illegaloperation: attempted to create a lock file on a read-only directory: /data/db, terminating
mongodb catalina
mongod no such file or directory
mac mongodb read only file system

I just finished installing MongoDB on OSX and setup a directory structure with sudo mkdir -p /data/db.

When I attempt to run mongod from my user account it returns an error stating that my user account does not have read/write permission to /data/db.

How can I set the proper read/write permissions on my account for /data/db?

Ensure that user account running mongod has the proper directory permissions. You can check which permissions are set like so:

ls -ld /data/db/

If they are set properly they should look something like this..

drwxr-xr-x X user wheel XXX Date Time /data/db/

If the permissions are set incorrectly you will likely see an error similar to this when attempting to run mongod

exception in initAndListen: XXXXX Unable to create/open lock file: /data/db/mongod.lock errno:13 Permission denied Is a mongod instance already running?, terminating

To get the permissions set as they should be you can run the following command

sudo chmod 0755 /data/db && sudo chown $USER /data/db

Setting read/write permissions on Mongodb folder - bash - iOS, I just finished installing MongoDB on OSX and setup a directory structure with sudo mkdir -p /data/db. When I attempt to run mongod from my user account it  It seems odd to me that the installer doesn't give "Write" permissions to a folder that is being used by the application that is getting installed - It's even more confusing that the folder that the installer creates in the ProgramData folder for the application's database doesn't get "Write" permissions.

sudo chmod 777 /data/db/ 

Should work on Mac. Before running this cmd, permissions look like

drwxr-xr-x  X User  wheel  Date /data/db

after running the cmd

drwxrwxrwx  X User  wheel  Date /data/db

Setting read/write permissions on Mongodb folder, I just finished installing MongoDB on OSX and setup a directory structure with sudo mkdir -p /data/db . When I attempt to run mongod from my  Set up the MongoDB environment.¶ MongoDB requires a data directory to store all data. MongoDB’s default data directory path is the absolute path \data\db on the drive from which you start MongoDB. Create this folder by running the following command in a Command Prompt:

This is what worked for me. I am using a Mac, although you could try if you're using windows.

sudo chmod 777 /data/db

Manage Users and Roles, To display the privileges granted to the user by the readWrite role on the "​accounts" database, issue: copy. copied. use accounts db.getRole( "readWrite"  Create a User-Defined Role¶. Roles grant users access to MongoDB resources. MongoDB provides a number of built-in roles that administrators can use to control access to a MongoDB system. However, if these roles cannot describe the desired set of privileges, you can create new roles in a particular database.

There are three categories of users: owners, those in the group, and everyone else; chmod 777 /path/to/file lets everyone read/write the file, but chmod 775 /path/to/file lets only the owner/group read/write the file. Definitely use chmod 775 /path/to/file if you're developing a web server.

Some useful reading, especially for reasoning behind why 777, 775, and so on are used rather than other numbers: https://www.maketecheasier.com/file-permissions-what-does-chmod-777-means/

Enable Access Control, Expire Data from Collections by Setting TTL Enabling access control on a MongoDB deployment enforces authentication, requiring The example MongoDB instance uses port 27017 and the data directory /var/lib/mongodb directory . the test database who has readWrite role in the test database as well as read role in  If the configuration file includes the __rest expansion, on Linux/macOS, the read access to the configuration file must be limited to the user running the mongod / mongos process only. __exec Allows users to specify a shell or terminal command as the external source for configuration file options or the full configuration file.

None of these suggestions are correct, there's something else wrong with mongodb-org-3.4.16-1.el7.x86_64. It cannot start with a custom db path.

[root@localhost vagrant]# chmod 777 /data/ /data/mongodb
[root@localhost vagrant]# chown mongod:mongod /data/ /data/mongodb
[root@localhost vagrant]# ls -lad /data/mongodb/
drwxrwxrwx. 2 mongod mongod 6 Jul 11 15:24 /data/mongodb/
[root@localhost vagrant]#  systemctl start mongod
Job for mongod.service failed because the control process exited with error code. See "systemctl status mongod.service" and "journalctl -xe" for details.
[root@localhost vagrant]# stat /data/mongodb^C
[root@localhost vagrant]# !tail
tail /var/log/mongodb/mongod.log
2018-07-11T15:39:10.786+0000 I STORAGE  [initandlisten] exception in initAndListen: 20 Attempted to create a lock file on a read-only directory: /data/mongodb, terminating
2018-07-11T15:39:10.786+0000 I NETWORK  [initandlisten] shutdown: going to close listening sockets...
2018-07-11T15:39:10.786+0000 I NETWORK  [initandlisten] shutdown: going to flush diaglog...
2018-07-11T15:39:10.786+0000 I CONTROL  [initandlisten] now exiting
2018-07-11T15:39:10.786+0000 I CONTROL  [initandlisten] shutting down with code:100
[root@localhost vagrant]# rpm -qa | grep mongo
mongodb-org-tools-3.4.16-1.el7.x86_64
mongodb-org-shell-3.4.16-1.el7.x86_64
mongodb-org-server-3.4.16-1.el7.x86_64
mongodb-org-mongos-3.4.16-1.el7.x86_64
mongodb-org-3.4.16-1.el7.x86_64

db.createUser(), user, document, The document with authentication and access information about the user readWrite access to the config database, which lets the user change  You can access these permissions by right-clicking on a file or folder, choosing Properties and then clicking on the Security tab. To edit permissions for a particular user, click on that user and then click the Edit button. Note that if the permissions are greyed out, like in the example above,

Atlas User Roles, Provides read-only access to the organization (settings, users, and billing) and the projects to which they belong. For an Organization Member , within a project,​  There are three categories of users: owners, those in the group, and everyone else; chmod 777 /path/to/file lets everyone read/write the file, but chmod 775 /path/to/file lets only the owner/group read/write the file.

service mongod cant start, permission denied mongod.lock when , sudo chown -R mongodb:mongodb /home/user/mongodb sudo service mongod sudo vi /etc/mongod.conf (inline dbPath change the path to "/{path}/mongo")  Restore a Replica Set from MongoDB Backups; Backup and Restore Sharded Clusters. Back Up a Sharded Cluster with File System Snapshots; Back Up a Sharded Cluster with Database Dumps; Schedule Backup Window for Sharded Clusters; Restore a Sharded Cluster; Recover a Standalone after an Unexpected Shutdown; Monitoring for MongoDB. Free Monitoring

Mongodb permissions error after changing data directory, user home directory as default can be read, write and listed only by his owner so other users (other that root user) can't event list content of  Setting the proper file permission for any web application is an important part of web hosting. In this tutorial, you will learn how to change file permissions on folder and sub-folders recursively in a single command. As you know, In Linux everything is treated as a file.

Comments
  • $ sudo chmod 0755 /data/db && sudo chown $USER /data/db
  • YES! do NOT forget sudo on chown!
  • What does wheel mean? Where you have User and Date in blue are those supposed to be replaced with something?
  • sudo chmod 0755 /data/db && chown $USER /data/db
  • should we not use this for the sake of security?!
  • Where you have ` $USER` is this the username for the database or the user account of the computer? Or do you literally type ` $USER`? :D Thanks.
  • What does where group is a group of your user mean? Please clarify.