Why can't my non admin users use mlocate command?

by ezgoodnight   Last Updated June 30, 2020 03:02 AM

I have a node.js software agent running on 14.04 not able to run many of his bash scripts on a new server. The problem I seem to have is the limited user returns nothing from the locate or mlocate command.

I need to figure out why this command works under my admin user but not under the agent's username.

[email protected] ~ $ locate 6831-7
/home/example/6831-7.txt
/home/example/6831-7.pdf
/home/example/6831-7.psd

[email protected] ~ $ sudo login limited
Password:
[email protected] ~ $ locate 6831-7

#it returns nothing

Nothing is returned to stdout, which is the problem I have with my scripts. What would cause this program to not return under this limited user?



Answers 2


Even though I added the user to the group, only this seemed to do the trick. I edited the permissions for the database with the following command:

sudo chmod o+r /var/lib/mlocate/mlocate.db

Provided that the database is located in /var/lib, this adds world read permissions to the database. The limited user was instantly able to return locate to stdout like normal.

Edit: The problem with this solution is that updatedb returns the world permissions to 0. So this is only a temporary solution.

ezgoodnight
ezgoodnight
January 19, 2016 21:46 PM

There is a bug report on this problem:

I didn't follow any of the suggestions there because I know how I had broken my system by using chown to $USER on / instead of /tmp/$USER/ recursively. It took a day to rebuild my system to boot. locate command is one of the left over things to fix.

Because my system is over-powered and under-utilized, I already have sudo updatedb running every 15 minutes via cron. So I just modified it to reset permissions.

Before change:

$ sudo ll /var/lib/mlocate/mlocate.db

-rw-r----- 1 root mlocate 110953861 Jun 29 20:02 /var/lib/mlocate/mlocate.db

Here's tail end of changes to crontab -e and what permissions look like:

# m h  dom mon dow   command
0   0   1   *   *     /bin/journalctl --vacuum-size=200M
*/15 *  *   *   *     nice updatedb && chmod o+r /var/lib/mlocate/mlocate.db
0  20   *   *   *     /sbin/fstrim /

$ while : ; do ll /var/lib/mlocate/mlocate.db ; sleep 5m ; done

-rw-r----- 1 root mlocate 110953861 Jun 29 20:02 /var/lib/mlocate/mlocate.db
-rw-r----- 1 root mlocate 110953861 Jun 29 20:02 /var/lib/mlocate/mlocate.db
-rw-r--r-- 1 root mlocate 110954083 Jun 29 20:15 /var/lib/mlocate/mlocate.db
-rw-r--r-- 1 root mlocate 110954083 Jun 29 20:15 /var/lib/mlocate/mlocate.db
-rw-r--r-- 1 root mlocate 110954083 Jun 29 20:15 /var/lib/mlocate/mlocate.db
-rw-r--r-- 1 root mlocate 110959759 Jun 29 20:30 /var/lib/mlocate/mlocate.db
-rw-r--r-- 1 root mlocate 110959759 Jun 29 20:30 /var/lib/mlocate/mlocate.db

This is just a band-aid until the root cause (pun noted) is found.

WinEunuuchs2Unix
WinEunuuchs2Unix
June 30, 2020 02:44 AM

Related Questions


Excluding hidden files in locate

Updated July 02, 2018 17:02 PM

Can't locate a directory using "locate"?

Updated July 19, 2016 08:00 AM

Get file path over ssh

Updated February 23, 2018 17:02 PM