Software⏱️ 2 min read📅 2026-05-31

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

Quick Answer: The issue is due to the file system being mounted as a different user than the root user. Try mounting the drive with the correct user, e.g., `sudo mount -t ext4 /dev/xvdf2 /data/mongod` and then run MongoDB as that user.

MongoDB's lock file is created in the /data/db directory, which is owned by the root user. Since you're running MongoDB as a non-root user, you don't have permission to access this directory.

🔍 Why This Happens

  • [Cause]

🚀 How to Resolve This Issue

Method 1: Change Ownership

  1. Step 1: Run the command `sudo chown -R mongo /data/db` to change the ownership of the /data/db directory from root to mongo.

Method 2: Use a Different Data Directory

  1. Step 1: Run the command `mongod --dbpath /mnt/data` to specify a different data directory. Make sure this directory is owned by the non-root user who's running MongoDB.

🎯 Final Words

By following one of these methods, you should be able to resolve the 'Unable to create/open lock file: /data/mongod.lock errno:13 Permission denied' error and get MongoDB up and running.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions