LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 01-10-2023, 03:14 AM   #1
axolinx
Member
 
Registered: Dec 2020
Posts: 55

Rep: Reputation: Disabled
Changing folder access - permission denied


Dear guys:

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.

Thank you!

Last edited by axolinx; 01-10-2023 at 03:16 AM.
 
Old 01-10-2023, 03:53 AM   #2
lvm_
Member
 
Registered: Jul 2020
Posts: 925

Rep: Reputation: 337Reputation: 337Reputation: 337Reputation: 337
To get to /media/alex/2TB/matt user matt must have 'x' permission not to just this folder but to all folders in this path.
 
Old 01-10-2023, 04:15 AM   #3
fatmac
LQ Guru
 
Registered: Sep 2011
Location: Upper Hale, Surrey/Hants Border, UK
Distribution: Mainly Devuan, antiX, & Void, with Tiny Core, Fatdog, & BSD thrown in.
Posts: 5,490

Rep: Reputation: Disabled
As above, the 'x' (executable) permission allows you to change through the directory path.

https://linuxhandbook.com/linux-file-permissions/

Last edited by fatmac; 01-10-2023 at 04:17 AM.
 
Old 01-10-2023, 04:26 AM   #4
axolinx
Member
 
Registered: Dec 2020
Posts: 55

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by fatmac View Post
As above, the 'x' (executable) permission allows you to change through the directory path.

https://linuxhandbook.com/linux-file-permissions/


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.
 
Old 01-10-2023, 05:01 AM   #5
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,791

Rep: Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201
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.
 
Old 01-10-2023, 05:39 AM   #6
axolinx
Member
 
Registered: Dec 2020
Posts: 55

Original Poster
Rep: Reputation: Disabled
@MadeInGermany

Thank you.

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.
 
Old 01-10-2023, 05:52 AM   #7
hazel
LQ Guru
 
Registered: Mar 2016
Location: Harrow, UK
Distribution: LFS, AntiX, Slackware
Posts: 7,573
Blog Entries: 19

Rep: Reputation: 4452Reputation: 4452Reputation: 4452Reputation: 4452Reputation: 4452Reputation: 4452Reputation: 4452Reputation: 4452Reputation: 4452Reputation: 4452Reputation: 4452
If it's a folder tree, you can use chmod -R on the root of the tree to change all the modes recursively.
 
Old 01-10-2023, 07:39 AM   #8
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,791

Rep: Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201
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.
 
2 members found this post helpful.
Old 01-10-2023, 11:03 AM   #9
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941
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.
 
1 members found this post helpful.
Old 01-10-2023, 01:17 PM   #10
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,791

Rep: Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
mkdir throws Permission Denied error in a directoy even with root ownership and 777 permission surajchalukya Linux - Security 14 09-03-2012 08:34 AM
du gives error : "du: cannot access `./.gvfs': Permission denied"du: cannot access `. MihirSahasrabudhe Linux - Security 4 12-29-2009 11:10 AM
can't execute c++ binaries, "permission denied"... even though permission is 777 SerfurJ Programming 14 02-20-2009 04:50 AM
'permission denied" inspite of right permission flags on network drive anirudhvij Linux - Enterprise 8 05-22-2007 05:57 AM
Folder Access Problems: Permission Denied piva.francesco Linux - Software 3 03-28-2006 12:11 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:10 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration