LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   cp: cannot stat: Permission denied, even though file is 644? (https://www.linuxquestions.org/questions/linux-newbie-8/cp-cannot-stat-permission-denied-even-though-file-is-644-a-759747/)

grayFalcon 10-05-2009 01:15 AM

cp: cannot stat: Permission denied, even though file is 644?
 
Hello everybody!

I've got a funny problem: I have some files lying around in /root/bla/, all these files are 644 and /root/bla/ is 755. Still, when I try (as a different user) to cp /root/bla/file ., I get a "cp: cannot stat: Permission denied". I also cannot ls /root/bla/, I also get a Permission denied... what gives?

Thanks a lot in advance,
grayFalcon

smeezekitty 10-05-2009 01:27 AM

chmod +r <file>
chmod +w <file>
chmod +x <file>
try those

lutusp 10-05-2009 01:47 AM

Quote:

Originally Posted by grayFalcon (Post 3707971)
Hello everybody!

I've got a funny problem: I have some files lying around in /root/bla/, all these files are 644 and /root/bla/ is 755. Still, when I try (as a different user) to cp /root/bla/file ., I get a "cp: cannot stat: Permission denied". I also cannot ls /root/bla/, I also get a Permission denied... what gives?

Thanks a lot in advance,
grayFalcon

The explanation is easy -- you don't have the permissions set as you describe.

1. If the directory permissions are 755 (rwxr-xr-x) including all parent directories, anyone can list the directory contents. But you can't, so the full directory path doesn't have 755 permissions.

2. If the files are 644 (rw-r--r--), then you can read them. But you can't, so either the files don't have 644 permissions. or requirement (1) above is not met.

To clarify -- if the entire path isn't listable by your user, you will get the result you got. So any parent directory without the execute bit set for your user will make it and all subdirectories unlistable. And files in the subdirectories will be unreadable.

So to read any particular file in a path, and to get directory listing for the path, the entire path must be parseable by your user.

If as root you see that a particular subdirectory is set to 755, this isn't enough to assure that a user will be able to list or read files in that directory. For that, all the parent directories must be readable by your user as well.

Now. Think about the fact that you are in the /root directory. Why would the root user open his home directory for anyone to browse?

On my system, the /root directory has drwxr-x--- permissions. Meaning? Ordinary users cannot browse or read that directory or any subdirectories. Members of the root group can browse and read files, but ordinary users cannot.

grayFalcon 10-05-2009 02:40 AM

Thanks! I did not realize that all parent directories have to be +x too... I was rather hoping to be able to expose only the one directory. Well, too bad.

Thanks again for the explanation,
-grayFalcon


All times are GMT -5. The time now is 11:47 AM.