# File ownership on an ext4 filesystem

**URL:** <https://forums.rockylinux.org/t/file-ownership-on-an-ext4-filesystem/11275>\
**Category:** Rocky Linux Help & Support\
**Created:** [September 12, 2023, 11:05pm UTC](https://forums.rockylinux.org/t/file-ownership-on-an-ext4-filesystem/11275 "2023-09-12T23:05:07Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![jbkt23](https://avatars.discourse-cdn.com/v4/letter/j/9fc29f/32.png) [@jbkt23](https://forums.rockylinux.org/u/jbkt23)\
**Post date:** [September 12, 2023, 11:05pm UTC](https://forums.rockylinux.org/t/file-ownership-on-an-ext4-filesystem/11275/1 "2023-09-12T23:05:07Z")

</div>

Is there any way to force a user created file to be of a specific group within a folder/directory or a particular mount point? Specifically on an ext4 file system. I can do this on cifs mounts. I’ve read man; mount, fstab and ext4. All those describe permissions for mounting but not subsequent file creation.

---

<div class="post-metadata">

**Author:** ![jbkt23](https://avatars.discourse-cdn.com/v4/letter/j/9fc29f/32.png) [@jbkt23](https://forums.rockylinux.org/u/jbkt23)\
**Post date:** [September 13, 2023, 12:41am UTC](https://forums.rockylinux.org/t/file-ownership-on-an-ext4-filesystem/11275/2 "2023-09-13T00:41:00Z")

</div>

So I found this thread here:  
[Set group permissions on folder](https://unix.stackexchange.com/questions/12842/make-all-new-files-in-a-directory-accessible-to-a-group)  
There are a few more steps based on other search results.

```auto
chgrp GROUPNAME /path/to/directory
chmod g+s /path/to/directory
find /path/to/directory -type d -exec chmod g+s {} +
setfacl -d -m group:GROUPNAME:rwx /path/to/directory
setfacl -m group:GROUPNAME:rwx /path/to/directory
find /path/to/directory -type d -exec setfacl -m d:g::rwx {} +

```

I still need to do some testing.

---

<div class="post-metadata">

**Author:** ![jbkt23](https://avatars.discourse-cdn.com/v4/letter/j/9fc29f/32.png) [@jbkt23](https://forums.rockylinux.org/u/jbkt23)\
**Post date:** [September 13, 2023, 1:35am UTC](https://forums.rockylinux.org/t/file-ownership-on-an-ext4-filesystem/11275/3 "2023-09-13T01:35:33Z")

</div>

OK, all is working. Groupname member user can create new file with groupname group ownership with rw permissions. Same with new folders which have setgid bit.

Hope this self answered question helps others as it did me.

---

<div class="post-metadata">

**Author:** ![jlehtone](https://avatars.discourse-cdn.com/v4/letter/j/e9a140/32.png) [@jlehtone](https://forums.rockylinux.org/u/jlehtone)\
**Post date:** [September 13, 2023, 2:41pm UTC](https://forums.rockylinux.org/t/file-ownership-on-an-ext4-filesystem/11275/4 "2023-09-13T14:41:26Z")

</div>

Yes, the setgid bit is nice, but not always enough.

The default is that created files do get the uid and gid of the process that creates them.  
The setgid bit overrides the gid with the gid of the directory, where the file is created (and sets the setgid bit, if created file is a directory).

However, that is for _created_ files. If you do _move_ existing file from elsewhere, it does already have gid set and likely retains that gid. (If you do `rsync -a`, then you definitely keep the existing gid, if possible.)

For that reason you want the FACL that the group of you choice does have write access in addition to POSIX attributes. (Although, `rsync -aA` can probably ruin that too. The rsync does have `--chown` and `--chmod` options.)

---

<div class="post-metadata">

**Author:** ![jbkt23](https://avatars.discourse-cdn.com/v4/letter/j/9fc29f/32.png) [@jbkt23](https://forums.rockylinux.org/u/jbkt23)\
**Post date:** [September 13, 2023, 10:14pm UTC](https://forums.rockylinux.org/t/file-ownership-on-an-ext4-filesystem/11275/5 "2023-09-13T22:14:56Z")

</div>

> [@jlehtone](#):
>
> If you do `rsync -a`, then you definitely keep the existing gid, if possible.)

That makes sense. I will have to test if the facl’s override that. The main use case is copy from desktop or downloads with what ever DE tools are involved. I do use scp and that does seem to conform to destination “ug” rules. I’ll test with -p to see what affect that has.

---

<div class="post-metadata">

**Author:** ![jbkt23](https://avatars.discourse-cdn.com/v4/letter/j/9fc29f/32.png) [@jbkt23](https://forums.rockylinux.org/u/jbkt23)\
**Post date:** [September 14, 2023, 12:50am UTC](https://forums.rockylinux.org/t/file-ownership-on-an-ext4-filesystem/11275/6 "2023-09-14T00:50:35Z")

</div>

I did some simple copies from local and remote hosts with basic copy and scp -p. In all cases the group was changed to the assigned group in the destination folder but the permissions remained unchanged from the source meaning if the source is 644 it remains as such. New files created by group members are created with group rw permissions.  
So I’m not quite there yet.

---

<div class="post-metadata">

**Author:** ![jlehtone](https://avatars.discourse-cdn.com/v4/letter/j/e9a140/32.png) [@jlehtone](https://forums.rockylinux.org/u/jlehtone)\
**Post date:** [September 14, 2023, 8:45am UTC](https://forums.rockylinux.org/t/file-ownership-on-an-ext4-filesystem/11275/7 "2023-09-14T08:45:00Z")

</div>

The permissions for new files do default to 777 and 666 (for directories and files, respectively) with _umask_ removed.

The RHEL default is that umask is 002, if effective groupname is equal to username. Others (and root) get 022.

The RHEL default is that the primary group of account (and hence usually the effective) has same name as the account. The _private_ group. Hence those users create files with 775 and 664 (and in setgid directory 2775 and 664).

* * *

The `scp` is no longer recommended, because it has some security issues. The sftp and rsync are better.

* * *

Did the copied files get the ACLs? Didn’t you have ACL to override the group’s permissions with g+rw?

* * *

PS. Read about permission `X` from `man chmod`. It helps as one does not have to chmod directories and files separately (for executability).

---

<div class="post-metadata">

**Author:** ![jbkt23](https://avatars.discourse-cdn.com/v4/letter/j/9fc29f/32.png) [@jbkt23](https://forums.rockylinux.org/u/jbkt23)\
**Post date:** [September 15, 2023, 3:16pm UTC](https://forums.rockylinux.org/t/file-ownership-on-an-ext4-filesystem/11275/8 "2023-09-15T15:16:00Z")

</div>

> [@jlehtone](#):
>
> The RHEL default is that umask is 002, if effective groupname is equal to username. Others (and root) get 022.

The default umask on RL9 is 022 in all cases for root or logged in user.

> [@jlehtone](#):
>
> Did the copied files get the ACLs? Didn’t you have ACL to override the group’s permissions with g+rw?

No, the copied file did not inherit the group g+rw set on the destination folder.

I haven’t looked at the chmod -X option. Since most file transfers are done through cifs shares the smb.conf settings are providing the correct group membership and perms upon file transfer.  
I was just trying to catch the edge case that is for the most part my own doing and not other users.

---

<div class="post-metadata">

**Author:** ![jlehtone](https://avatars.discourse-cdn.com/v4/letter/j/e9a140/32.png) [@jlehtone](https://forums.rockylinux.org/u/jlehtone)\
**Post date:** [September 15, 2023, 4:00pm UTC](https://forums.rockylinux.org/t/file-ownership-on-an-ext4-filesystem/11275/9 "2023-09-15T16:00:19Z")

</div>

> [@jbkt23](#):
>
> The default umask on RL9 is 022 in all cases for root or logged in user.

Oh my, how have I missed that? 😵‍💫

Thanks for correcting.

---

<div class="post-metadata">

**Author:** ![jlehtone](https://avatars.discourse-cdn.com/v4/letter/j/e9a140/32.png) [@jlehtone](https://forums.rockylinux.org/u/jlehtone)\
**Post date:** [September 18, 2023, 12:38pm UTC](https://forums.rockylinux.org/t/file-ownership-on-an-ext4-filesystem/11275/10 "2023-09-18T12:38:15Z")

</div>

> [@jlehtone](#):
>
> how have I missed that?

EL9 did set umask for _non-login shells_ differently from login shells, until  
[https://access.redhat.com/errata/RHBA-2023:2552](https://access.redhat.com/errata/RHBA-2023:2552) that is EL 9.2, last May.

```plaintext
* Thu Oct 24 2022 Martin Osvald <mosvald@redhat.com> - 2.13.7-8
- Set default umask for non-login shell only if it is set to 0 (#2062601)

```

Interestingly, the RHEL 9 docs are still [https://access.redhat.com/documentation/en-us/red\_hat\_enterprise\_linux/9/html/configuring\_basic\_system\_settings/assembly\_managing-the-umask\_configuring-basic-system-settings](https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/9/html/configuring_basic_system_settings/assembly_managing-the-umask_configuring-basic-system-settings) with old content.

* * *

Regardless, if I create file from command-line with umask 0002, it does get g+w, but if I use the GNOME Files GUI, it acts g-w. That too is inconsistent (and I tend to miss it as I dont’ usually use GUI).

* * *

Tested on ext4:

```bash
$ mkdir xxx
$ setfacl -d -m group:ptest:rwx xxx

```

Copied two files; one with `cp`, other with ‘Files’, i.e. “drag-n-drop”.

```bash
$ getfacl xxx/f*
# file: xxx/file_trans_eplg.sh
# owner: jlehtone
# group: jlehtone
user::rw-
group::rwx #effective:r--
group:ptest:rwx #effective:r--
mask::r--
other::r--

# file: xxx/file_trans_prlg.sh
# owner: jlehtone
# group: jlehtone
user::rw-
group::rwx #effective:r--
group:ptest:rwx #effective:r--
mask::r--
other::r--

```

Both files did get the `group:ptest:rwx` ACL.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex020/uploads/rockylinux/original/1X/91b7219eec10e30013422e4df76c1d898711a5d5.svg) [@system](https://forums.rockylinux.org/u/system)\
**Post date:** [November 17, 2023, 12:38pm UTC](https://forums.rockylinux.org/t/file-ownership-on-an-ext4-filesystem/11275/11 "2023-11-17T12:38:33Z")

</div>

Closed on November 17, 2023, 12:38pm UTC

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
