Reputation: 7119
I'm trying to restart (it is running) MongoDB on Ubuntu 14.04 but keep getting failures with this line in the log error getting file /srv/mongodb/keyfile: Permission denied
Here's directory structure
drwxr-xr-x 3 root root 4096 Jan 31 05:54 srv/
drw------- 2 mongodb mongodb 4096 Jan 31 07:07 mongodb/
-rw------- 1 mongodb mongodb 876 Jan 31 07:07 keyfile
The user running mongod
is "mongodb", group "mongodb" so it should be available for reading.
If I change permissions on mongodb/
and keyfile
to -rw-r--r--
it becomes readable, but mongo claims it's too permissive of course
Going cookoo with this thing already. Any suggestion what's wrong here?
Upvotes: 7
Views: 13487
Reputation: 449
As I wrote in this post, the comment was right, mongo needs permissions not only in the keyfile, but in the directory:
I have just moved my keyfile from my home user /home/user/keyfile to a directory where mongodb is owner: /var/lib/mongodb/keyfile. Also remember keyfile must have 400 permissions and be owner and group of mongodb: chmod 400 keyfile chwon mongodb:mongodb keyfile
Upvotes: 2
Reputation: 868
I got the mongod service working by changing the owner of the key file to mongod
sudo chown mongod:mongod mongodb.key
the mongod process owner is mongod which tries to access the file
Upvotes: 8
Reputation: 1584
Since none of the answers here solved my problem, and I had the same problem exactly, I'll try to post what worked for me.
My solution:
mongod.conf
and temproraily comment out the attribute keyFile: /path/to/key
sudo chown mongod </path/to/key>
sudo chmod 400 </path/to/key>
KeyFile
attribute in mongod.conf
Hope this helps
Upvotes: 2
Reputation: 552
I've had the same problem before, and the solution I found and was not documented had to do with the context. If you are in Linux try:
ls -lahZ
That will display in list, all files, sizes in human readable and Z for contexts, I noticed that the keyFile must have "system_u:object_r:mongod_var_lib_t:s0" context, so it gets fixed with:
chcon system_u:object_r:mongod_var_lib_t:s0 mongodb-keyfile
Hope that helps!!
Upvotes: 16
Reputation: 3692
In addition to read and write permission for a directory, usually you must have an execute permission as well (more info at http://en.wikipedia.org/wiki/File_system_permissions#Permissions). So, you have to set the following permissions:
chmod 700 /srv/mongodb/
chmod 600 /srv/mongodb/keyfile
Upvotes: 4