0

I was trying to find all the users in my Gnu/Linux system that have access to one particular folder.

I tried

$ ls -ld */
dr-xr-xr-x.   2 root root     28672 Mar 20 21:33 bin/
dr-xr-xr-x.   4 root root      4096 Mar 16 16:02 boot/

I tried ls -ldd */ , but it list only 1 row for one folder with the user name with which it created.

But I was expecting to list one folder each will show all users names who can access this folder

Eg:

$ 
dr-xr-xr-x.   2 user1 user1     28672 Mar 20 21:33 bin/
dr-xr-xr-x.   2 user2 user2      28672 Mar 20 21:33 bin/

Is there any way to do this?

10
  • Can you be more specific to the meaning of "has access"? Is it read access? write access? execute access? Any other type of access? Commented Mar 24, 2020 at 20:26
  • 2
    Since the directories are readable by "other", everyone has access. Commented Mar 24, 2020 at 20:42
  • What are the permissions of the parent folder(s)? Commented Mar 24, 2020 at 20:48
  • @PauloTomé ls -ld */. will show the access (dr-xr-xr-x) at the very left side of output.I was looking for any command that will show a similar output but to find all the users who has access to one specific folder. Commented Mar 24, 2020 at 21:06
  • 2
    If you are talking groups ... you will need to loop though each userid defined through getent and issue a id to get the groups the userid belongs to, then compare the directory group with userid groups
    – rr0ss0rr
    Commented Mar 24, 2020 at 21:11

1 Answer 1

0

Quick and Dirty and only tested on a Mac (which doesn't use getent). I replaced getent with the mac command to test "dscl . -ls /Users"

chkgrp=$1
for userid in $(getent passwd); do
   echo "$(id -Gn $userid)" | grep -wq $chkgrp
   [[ $? -eq 0 ]] && echo "$userid is in the $chkgrp group"
done

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .