LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   chmod - dir permission (https://www.linuxquestions.org/questions/linux-software-2/chmod-dir-permission-4175619468/)

czezz 12-12-2017 05:15 PM

chmod - dir permission
 
Is there a way to set permission to dir, so that every file created in this dir can be overwritten by another user? User with different group.

czezz 12-13-2017 07:13 AM

[UPDATE]

The reason why I am asking is that I want to partition USB drive with EXT4 (Actually, I want to encrypt drive with LUKS and make ext4 file system inside).
That however works good only when I am a root user.
As soon as I switch to regular user it starts with permission issues. (even when I do chmod 1777 to the whole file system).

As a workaround, I can use NTFS partition but I would rather keep to native Linux file systems.

giis 12-13-2017 07:23 AM

Have you tried setfacl command? https://wiki.archlinux.org/index.php..._Control_Lists

kilgoretrout 12-13-2017 10:40 AM

As giis suggested, you have to set the ACL on the mountpoint of your encrypted partition to allow an ordinary user to access it:
Code:

# setfacl -m "<username>:rw" <mountpoint>

pan64 12-13-2017 10:53 AM

There are two different possibilities: 1. you want to edit/modify files, these depends on the permissions of those files, so the answer is no.
2. you want to remove/delete that file and create it again (as another user). It may only depend on the permission of the dir, obviously 777 on that dir will allow that.

rknichols 12-13-2017 11:25 AM

Quote:

Originally Posted by pan64 (Post 5792699)
There are two different possibilities: 1. you want to edit/modify files, these depends on the permissions of those files, so the answer is no.

You can also set a "default" ACL on the directory. Permissions that you set there will be inherited by any new files.

kilgoretrout 12-14-2017 09:33 AM

For anyone interested, came across this good article on using ACLs to address this type of problem:

https://www.2daygeek.com/how-to-conf...getfacl-linux/

czezz 12-14-2017 09:49 AM

Hi, thanks for replies. I tried setfacl but it didnt really work as expected.

Code:

$ sudo setfacl -m "user1:rw" /mnt/x
$ ls -al /mnt/
total 12
drwxr-xr-x  3 root root 4096 Dez 14 16:25 .
drwxr-xr-x  24 root root 4096 Dez 12 14:26 ..
drwxrwxr-x+  3 root root 4096 Dez 14 16:22 x

$ ls -al /mnt/x/
ls: cannot access '/mnt/x/lost+found': Permission denied
ls: cannot access '/mnt/x/..': Permission denied
ls: cannot access '/mnt/x/.': Permission denied
total 0
d????????? ? ? ? ?            ? .
d????????? ? ? ? ?            ? ..
d????????? ? ? ? ?            ? lost+found

$ touch /mnt/x/test1
touch: cannot touch '/mnt/x/test1': Permission denied

$ sudo tune2fs -l /dev/sdb | grep options
Default mount options:    user_xattr acl


giis 12-14-2017 10:31 AM

Can you share the output of getfacl on the directory? Does it show newly added permission?

rknichols 12-14-2017 06:51 PM

Without execute permission, all you can do is list the names in the directory. You can't use the directory to access the file's inode or data blocks, so ls can't get any information about the file.

czezz 12-15-2017 06:21 AM

I have added "execute" to that dir.
Code:

$ sudo getfacl /mnt/x
getfacl: Removing leading '/' from absolute path names
# file: mnt/x
# owner: root
# group: root
# flags: --t
user::rwx
user:user1:rwx
group::r-x
mask::rwx
other::rwx


Now:
1. my user can edit files belonging to "root"
2. if my user create file, only him or users on other system with this same uid and gid can edit this file.
3. if USB drive mounted on another system where mount point has no acl set up, and the user has different uid and gid than the one I use on my system, none of files are editable. Moreover it creates files in read only mode (for himself).
Code:

$ ls -al /mnt/x/
total 36
drwxrwxrwt+ 3 root    root    4096 Dez 15 13:13 .
drwxr-xr-x  3 root    root    4096 Dez 14 16:25 ..
drwxrwxrwt  2 root    root    16384 Dez 14 16:22 lost+found
-rwxrwxrwt  1 root    root        7 Dez 15 12:58 test1
-rw-rw-r--  1 user1 user1    11 Dez 15 13:05 test2
-rw-r-----  1    1003    1003    7 Dez 15 13:11 test3

Im afraid NTFS will be the only solution, so I can connect this drive to any other systems.

pan64 12-15-2017 06:31 AM

you are mixing now the permission settings of mount (and directories). That is a different issue, and in your case it looks like it is more restrictive. Using different filesystem(s) like NTFS will not auto-magically solve this issue, although it may have different defaults as the currently used filesystem.
File creation is ruled by umask (which is a third issue).

rknichols 12-15-2017 08:49 AM

You have to set the ACL while the USB filesystem is mounted. The root inode of the mounted filesystem covers up the the mount point directory, so anything you set on that mount point directory is irrelevant.

If the numeric UIDs are not the same on all the systems, you have to add an ACL for each numeric ID. Life is a lot easier if you keep the UIDs in sync.

You can also add a "default" ACL to the mounted directory, and those access permissions will be inherited by any newly created files.

czezz 12-15-2017 10:23 AM

Hi guys, many thanks for your replies.

Mount point on my system is /mnt/x
Obviously on any other systems it will be whatever else AND I have no root access there. Also users (uid/gid) will be different too.
By executing $ sudo setfacl -m "user1:rwx" /mnt/x , I understand Im setting ACL to the root of my USB driver (while its mounted).

I have already tested with NTFS - in that case any user can modify/delete any files with no matter of its permissions.
And that is my goal (although I would prefer to have native Linux fs).

MadeInGermany 12-15-2017 02:43 PM

As root:
Mount your device on /mnt/x
Remove all ACLs with
Code:

setfacl -b /mnt/x
Open it for world
Code:

chmod 777 /mnt/x
Set 3 default ACLs, so it is inherited to new directories
Code:

setfacl -m default:user::rwx /mnt/x
setfacl -m default:group::rwx /mnt/x
setfacl -m default:other::rwx /mnt/x

check with
Code:

getfacl /mnt/x

# file: /mnt/x
# owner: root
# group: root
user::rwx
group::rwx
other::rwx
default:user::rwx
default:group::rwx
default:other::rwx



All times are GMT -5. The time now is 11:38 PM.