ChatGPT is wrong, because it cannot understand that words have different meanings to different people.
The commonsense meaning of read access is different from the technical meaning of read permissions.
Surprisingly, access to a directory is determined by execute, not read, permissions. A lack of directory read permissions only prevents listing unknown contents, not access to them.
So in addition to adding read access to the files and directories, you also need to add a capital X
to add execute permissions only for the directories, not the files:
chmod -R go+rX mydir
The -R
means recursive, it applies to all files and directories within.
The go+
adds those permissions for every user (the g
means including those in the same group as the file, just in case).
But that might still not be enough.
All parent directories of the directory to be shared will also require execute permissions to allow access to the inner directory, which I'm assuming in this case is somewhere within your home directory.
You cannot allow access to your cupboard without allowing access into your home (directory), though you may already be allowing this.
You can lock all the other doors (the read, write, and execute permissions of files and other sub-directories), and you can leave the lights off (that directory's read and write permissions), but by guessing filenames, people can still feel their way around the corridor from different error messages even if they cannot peek inside the rooms:
$ ls parent_dir
ls: cannot open directory 'parent_dir': Permission denied
$ cat parent_dir/exists
cat: parent_dir/exists: Permission denied
$ cat parent_dir/doesn\'t
cat: "parent_dir/doesn't": No such file or directory
And even if you carefully lock all those inner doors, new unlocked doors might be created by programs you later run.
So I'm not sure you want to do this, but to make the inner directory accessible to every user:
chmod go+X mydir/..
chmod go+X mydir/../..
etc, up to and including /home/$USER
.
What you might want instead
If you maybe now want to only trust a specific user, not everyone, you could create a special case with ACLs instead:
setfacl -m OTHER_USERNAME:X mydir/..
setfacl -m OTHER_USERNAME:X mydir/../..
etc, again up to and including /home/$USER
.
You could even remove this as soon as they are done copying, with:
setfacl -x OTHER_USERNAME mydir/..
etc.
But then if you really just wanted to allow someone to make a one-time copy of it, and the directory isn't too large, it would be much easier to just copy it to /var/tmp
, run chmod -R go+rX /var/tmp/mydir
, then delete it when the other user is done copying from that.