0

I have two users on a Ubuntu machine. One of them is in sudoers list, while the other is not. I create a directory in first user's home directory. Then I change the ownership of this directory to the other user. Now when I switch to the other user and try to read this directory, it says permission denied.

I used chown with -R so it applied to everything inside the directory.

The ls -l shows this

drwxr-xr-x 2 lfs  lfs   4096 Mar 23 02:07 sources

lfs being the second user.

  • 2
    Does the parent directories of the "source" directory have execute permissions for the other user? – Kusalananda Mar 23 '18 at 14:13
  • Concur with @Kusalananda - check the entire tree leading up to that directory. Chances are that's why you're getting locked out. – Shadur Mar 25 '18 at 19:43
2

This is a follow-up to @Kusalananda 's question in the comment associated with your question above.

Suppose that you have two users, user1 and user2. Suppose that user1 has a home directory /home/user1. Now suppose that in the home directory of user1 you create a directory owned by user2, say /home/user1/sources, can user2 access that directory?

In order for user2 to be able to access /home/user1/sources, then user2 needs to have x (traverse) permission on each directory from root, up to and including the sources directory:

$ ls -ld /
dr-xr-xr-x 31 root root 4096 Feb 28 11:37 /
         ^ Check (this will almost always be OK)

$ ls -ld /home
drwxr-xr-x 4 root root 4096 Feb 28  11:38 /home
         ^ Check (this will almost always be OK)

$ ls -ld /home/user1
drwx------ 9 user1 group1 4096 Mar 21 00:36 /home/user1
      ^  ^ In this case, no, user2 cannot traverse here

$ ls -ld /home/user1/sources
drwxr-xr-x 9 user2 group2 4096 Mar 21 00:36 /home/user1/sources
   ^ Check

In this example, because user2 cannot traverse into /home/user1, user2 cannot access /home/user1/sources (even though user2 owns that directory).

In your question you said that the sources directory is in the home directory of the first user. My guess is that the second user can't access the first user's home directory.

You might consider putting the sources directory somewhere outside of the user's home directory.

  • Thank you. :) i had to use /mnt to create the sources for user lfs to be able to read. – Akash Garg Mar 27 '18 at 1:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.