LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 03-12-2010, 03:56 AM   #1
aditya007
LQ Newbie
 
Registered: Nov 2009
Posts: 5
Blog Entries: 1

Rep: Reputation: 0
locate command is giving error while "user!=ROOT" .....


Hi, Naman here...

problem:

when I am using "LOCATE" command in linux command promt,like..

~]$ locate file1.txt
locate: can not open `/var/lib/mlocate/mlocate.db': Permission denied


This error(in red color)is occurred.

when I am doing as a root user....it gives result,
without any errors.

Would any one help me?
~~~~

Last edited by aditya007; 03-12-2010 at 04:01 AM.
 
Old 03-12-2010, 05:46 AM   #2
trappa01
LQ Newbie
 
Registered: Dec 2009
Posts: 20

Rep: Reputation: 8
Hi,
I think that you'll find that /var/lib/mlocate/mlocate.db cannot be accesses by "normal users". Whilst root check the owner and group of the db file.
Do a "which locate" to find the file that you are actually running. It is probably a link that points to another executable. Check the rights to this file. It should be owned by root and have the same group as the .db file. It should also have the SetGID set to on.
I've just checked on one of our machines (we have slocate and not mlocate but the principle should be the same).

example
[root@host1 ~]# ls -l /var/lib/slocate/slocate.db
-rw-r----- 1 root slocate 843345 Sep 12 2008 /var/lib/slocate/slocate.db
[root@host1 ~]# which locate
/usr/bin/locate
[root@host1 ~]# ls -l /usr/bin/locate
lrwxrwxrwx 1 root slocate 7 Jan 14 16:07 /usr/bin/locate -> slocate
[root@host1 ~]# ls -l /usr/bin/slocate
-rwxr-sr-x 1 root slocate 38516 Aug 22 2007 /usr/bin/slocate
 
Old 03-12-2010, 06:01 AM   #3
arashi256
Member
 
Registered: Jan 2008
Location: Brighton, UK
Distribution: Ubuntu 12.04 / CentOS 6.5
Posts: 384

Rep: Reputation: 61
You need to be the root user for locate to look in those directories.
 
Old 03-12-2010, 06:24 AM   #4
jamescondron
Member
 
Registered: Jul 2007
Location: Scunthorpe, UK
Distribution: Ubuntu 8.10; Gentoo; Debian Lenny
Posts: 961

Rep: Reputation: 69
No you don't

Code:
jc@jcmain:~$ locate mtab|head 
/etc/mtab
/etc/init.d/mtab.sh
/etc/init.d/udev-mtab
/etc/rcS.d/S12mtab.sh
/etc/rcS.d/S36udev-mtab
/home/redundant/toolbox/commblks/commblksdemos/commwcdma_lib_primenumtable.mat
/home/redundant/toolbox/compiler/mcr/matlab/iofun/@rptgen/@rptsummtable
/home/redundant/toolbox/compiler/mcr/matlab/iofun/@rptgen/@rptsummtable/execute.m
/home/redundant/toolbox/compiler/mcr/matlab/iofun/@rptgen/@rptsummtable/execute.p
/home/redundant/toolbox/compiler/mcr/matlab/iofun/@rptgen/@rptsummtable/getContentType.m
All of these files are in directories I don't own, yet I can run locate as a normal user (to coin a phrase).

This is an odd one, somewhere your permissions are dodgy, as trappa said. Watch:
Code:
jc@jcmain:~$ updatedb
updatedb: can not open a temporary file for `/var/lib/mlocate/mlocate.db'
jc@jcmain:~$ ls -l  /var/lib/mlocate/mlocate.db
-rw-r----- 1 root mlocate 17352445 2010-03-12 07:39 /var/lib/mlocate/mlocate.db
See, I can't run updatedb without being root because that updates the database backend. However, I can run 'locate' (as seen above).

Chances are, the problem is in how your slocate group is setup, though I can't tell you for sure, never having had this problem.
 
Old 03-12-2010, 06:41 AM   #5
arashi256
Member
 
Registered: Jan 2008
Location: Brighton, UK
Distribution: Ubuntu 12.04 / CentOS 6.5
Posts: 384

Rep: Reputation: 61
Oops - James gets a cookie. Just tried something similar on my system and he's right. Ignore what I said
 
Old 03-12-2010, 07:32 AM   #6
trappa01
LQ Newbie
 
Registered: Dec 2009
Posts: 20

Rep: Reputation: 8
James,
could you do a "which locate", then "ls -l" the resulting file. If its a link, please do a "ls -l" of the target too.

Thanks
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting bash to login as root and recognize commands like "vi" and "locate" ajaygoeslinux Linux - Software 4 05-04-2009 10:51 PM
SUSE 11.0 - "SU" command giving error for installation through YAST raju.mopidevi Suse/Novell 2 01-26-2009 08:07 AM
run "locate" command error ust Linux - Software 9 07-03-2008 01:21 AM
Standard commands give "-bash: open: command not found" even in "su -" and "su root" mibo12 Linux - General 4 11-11-2007 10:18 PM
Postgresql error FATAL: user "root" does not exist" cgetty Ubuntu 4 06-21-2005 02:11 PM


All times are GMT -5. The time now is 04:40 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration