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.
📋 Table of Contents
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
- 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
- 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.
❓ Frequently Asked Questions
Step 1: Run the command `sudo chown -R mongo /data/db` to change the ownership of the /data/db directory from root to mongo.
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.
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.
🛠️ Related Fixes
How to Fix: Pc crashes shortly after launching game (rainbow
Pc crashes shortly after launching game, possible cause: outdated grap
How to Fix: Installing an APK on a locked down phone
Installing an APK on a locked down phone: Try using a rooted device, e
How to Fix: FPS drops
FPS drops in games can be caused by high system resource usage, outdat