Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
My scenario: Linux Mint 20.3
Two users (alex and matt)
A secondary hard drive mounted under /media/alex/2TB (mounted by alex)
I am trying to give access to a specific folder for matt. so this folder is
here: /media/alex/2TB/matt
I changed the folder ownership to matt:
Code:
chown -R matt:matt /media/alex/2TB/matt
Now i can see:
Code:
alex@stationX:/media/alex/2TB$ ll
total 52
drwx------ 10 alex alex 4096 Jan 9 10:36 ./
drwxr-x---+ 3 root root 4096 Dec 12 05:35 ../
drwxrwxr-x 27 alex alex 4096 Aug 2 23:58 'alex data'/
drwx------ 2 root root 16384 Aug 2 18:06 lost+found/
drwxrwxr-x 2 matt matt 4096 Jan 10 02:19 matt/
But then i login with the user matt, and i get permission denied to access that folder:
Code:
matt@stationX:~$ cd /media/alex/2TB/matt
-bash: cd: /media/alex/2TB/matt: Permission denied
I know i can try changing the folder permissions like:
sudo chmod -R ugo+rw /media/alex/2TB/matt
But i would like to understand what i am doing wrong and why changing the owner to that folder still does not allow access to it.
The x was already set for UGW. I do not understand.
Now i actually changed the folder to 777 and still do not have permission for matt
Code:
drwxrwxrwx 2 matt matt 4096 Jan 10 02:19 matt/
I must add a bit more info, it may matter:
This is an encrypted drive (LUKS), so alex is the one mounting it and providing the passphrase for it.
matt needs access to that folder to pull a 40GB file that i can not just move to his home folder because the main disk is low on disk space, matt needs to have a way to access that folder.
Not that folder!
The access is denied by the top folder, marked in red:
Code:
alex@stationX:/media/alex/2TB$ ll
total 52
drwx------ 10 alex alex 4096 Jan 9 10:36 ./
drwxr-x---+ 3 root root 4096 Dec 12 05:35 ../
drwxrwxr-x 27 alex alex 4096 Aug 2 23:58 'alex data'/
drwx------ 2 root root 16384 Aug 2 18:06 lost+found/
drwxrwxr-x 2 matt matt 4096 Jan 10 02:19 matt/
The suggestion was to add x (access) permission to it
Code:
chmod +x /media/alex/2TB
And perhaps to the next higher directories
Code:
chmod +x /media/alex
chmod +x /media
x without r means access without list/browse - you must know the directory names inside because you cannot read them.
The +x will allow ALL users access though. So do not have worldwide open directories and files in the tree below!
A more restrictive alternative is to just allow access for group alex and add user matt to group alex:
Code:
chmod 750 /media/alex/2TB
usermod -a -G alex matt
The 5 is g=rx and gives the group even list/browse access. The 0 denies access for all others.
Last edited by MadeInGermany; 01-10-2023 at 05:03 AM.
Adding matt to the alex group alone did not help,
but then i set X for each folder in the path and now matt can reach the folder.
I think I knew folders need to have x permission in order to be browsed, need to pay more attention.
So when giving access to a local owned folder to another user, each step in the path needs to have the X for "others" right?
Is there a way to do this in one shot issuing the command to the specific folder, or you need to chmod each folder individually like i did?
Thanks again, my problem is solved.
chmod -R is dangerous if you do not know about all of its consequences.
E.g. -x sets x bits on files and directories, this is hardly ever wanted; in Linux there is -X for only directories, but nothing for only files.
There is an x-bit for each of user,group,others.
If you are the owner then the user permissions rule. If you are not the owner but belong to the group then the group permissions rule. If you are neither owner nor group member then the permissions for others apply.
Last edited by MadeInGermany; 01-10-2023 at 09:55 AM.
FYI: Group permissions are most commonly used for higher-level directories, because a user can belong to more than one group. Then, when you get into the target parent-folder, you use User permissions to control access.
Also for what it's worth, most Linux (and, other ...) filesystems also support ACLs = Access Control Lists, which are a parallel but much more versatile and fine-grained mechanism for controlling permissions and access. Unfortunately, they are inconsistent in their features and implementations.
Effective implementation is standardized in POSIX ACLs.
But support for copying/archiving/backup is pretty much individual.
Further, ACLs are complicated. An overuse of ACLs can make it difficult for humans to determine who has access.
I have decided to use ACLs as little as possible.
The most frequent case, a shared group-writable folder tree, I have documented here.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.