Software⏱️ 4 min read📅 2026-06-03

How to Fix: Unable to create/open lock file: /data/mongod.lock errno:13 Permission denied

Quick Answer: The issue is due to the permissions on the /data/db directory. The 'mongod.lock' file is being created in this directory, but the process running as root cannot write to it because of the restrictive permissions. To fix this, you need to change the ownership and permissions of the /data/db directory to allow writing by the mongod process.

The 'Unable to create/open lock file: /data/mongod.lock errno:13 Permission denied' error occurs when MongoDB is unable to write or read files in the specified directory due to lack of permissions. This issue affects users who have mounted a drive on their EC2 instance and are running MongoDB on Ubuntu 12.04.

This error can be frustrating, especially when troubleshooting other issues with your MongoDB setup. In this guide, we will walk you through the steps to resolve this issue by changing the ownership of the /data directory and adjusting file permissions.

🔍 Why This Happens

  • The primary reason for this error is that the MongoDB data directory (/data/db) does not have the correct permissions set. By default, the owner of the directory has read-only access, preventing MongoDB from writing to it.
  • Another possible cause is that the user running MongoDB (usually 'root' on Ubuntu 12.04) does not have the necessary permissions to write to the /data directory.

🔧 Proven Troubleshooting Steps

Change ownership and adjust file permissions

  1. Step 1: Change the ownership of the /data/db directory from root:root to the current user (usually 'root') using the command `sudo chown -R root:root /data/db`. This sets the owner to 'root', but we need to change it to the current user.
  2. Step 2: Next, change the group ownership of the /data/db directory to the same as the current user using the command `sudo chgrp -R $USER /data/db`. Replace '$USER' with your actual username.
  3. Step 3: Adjust file permissions for the /data/db directory by running the command `sudo chmod -R 755 /data/db`. This sets the owner, group, and read, write, and execute permissions to ensure that the current user can write to the directory.

Alternative fix using mount options

  1. Step 1: If changing ownership and file permissions does not resolve the issue, try adjusting the mount options for the mounted drive. You can do this by editing the /etc/fstab file. Add the following line at the end of the file: `mongodb /data ext4 defaults,noatime,nodiscard,x-systemd.automount,x-systemd.device-timeout=10 0 2`. Replace 'mongodb' with your actual MongoDB data directory name.
  2. Step 2: Restart MongoDB by running the command `sudo service mongodb restart` or `sudo systemctl restart mongodb`. This may take a few minutes to complete.

🎯 Final Words

To resolve the 'Unable to create/open lock file: /data/mongod.lock errno:13 Permission denied' error, change the ownership of the /data/db directory and adjust file permissions. Alternatively, try adjusting mount options for the mounted drive if changing ownership does not work. By following these steps, you should be able to resolve this issue and get MongoDB running smoothly on your EC2 instance.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions