Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Permission denied to read file owned by user

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?

like image 490
Eugene Kostrikov Avatar asked Jan 31 '15 12:01

Eugene Kostrikov


2 Answers

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!!

like image 160
jmdiego Avatar answered Oct 16 '22 11:10

jmdiego


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

like image 33
rishabhr0y Avatar answered Oct 16 '22 12:10

rishabhr0y