Page 2 of 2 FirstFirst 12
Results 11 to 19 of 19

Thread: umask, file copy, file creation, directory creation - I'm confused, please help

  1. #11
    Join Date
    Mar 2010
    Location
    Squidbilly-Land
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: umask, file copy, file creation, directory creation - I'm confused, please help

    Quote Originally Posted by ml9104 View Post
    I feared that answer.
    External storage can be anything, but mostly files from FAT/NTFS systems. My hope was that it's possible to force permissions when copying from external sources. Why not? M$ files don't even have those attributes.
    Another source is downloads from the Web. Resulting permissions are also no good.
    You can force the permissions used on Unix systems .... via the mount options. This is well traveled and well answered in the different mount manpages AND in hundreds of forum posts here.

    Whenever there are permissions issues, the first question must be - what file system is involved.
    The 2nd question is local or network access - if networked, which protocol is being used? NFS supports POSIX permissions to POSIX file systems. CIFS works like all non-POSIX solutions - the permissions are forced through the mount/share options.

    That is just the way it is with non-POSIX stuff.

  2. #12
    Join Date
    Dec 2009
    Beans
    6,556

    Re: umask, file copy, file creation, directory creation - I'm confused, please help

    External storage can be anything, but mostly files from FAT/NTFS systems. My hope was that it's possible to force permissions when copying from external sources.
    Try the following experiment: Eveything you do here can be unmounted and un-done so it's not permamant.

    Install bindfs:
    Code:
    sudo apt install bindfs
    Create a mount point in say your home directory - can be anywhere:
    Code:
    mkdir /home/tester/MyMedia
    Temporarily mount your /media/$USER directory to MyMedia using bindfs specifying a different set of permissions:
    Code:
    sudo bindfs -o perms=0660:+D,force-user=tester,force-group=tester,nonempty /media/tester /home/tester/MyMedia
    I have a file labeled ntfs-test.txt located at /media/tester/DataN. Since it's formatted ntfs it will exhibit the default ntfs permissions:
    tester@vxub2004:~$ ls -l /media/tester/DataN/ntfs-test.txt
    -rwxrwxrwx 1 tester tester 0 Jun 13 08:07 /media/tester/DataN/ntfs-test.txt
    If I look at the bindfs remount it will exhibit the permissions I specified:
    tester@vxub2004:~$ ls -l /home/tester/MyMedia/DataN/ntfs-test.txt
    -rw-rw---- 1 tester tester 0 Jun 13 08:07 /home/tester/MyMedia/DataN/ntfs-test.txt
    If I were to copy that file from MyMedia/DataN to my Public folder it will retain the permissions set by bindfs:
    tester@vxub2004:~$ cp /home/tester/MyMedia/DataN/ntfs-test.txt Public
    tester@vxub2004:~$ ls -l Public/ntfs-test.txt
    -rw-rw---- 1 tester tester 0 Jun 13 08:15 Public/ntfs-test.txt
    To stop all this unmount it:
    Code:
    sudo umount /home/tester/MyMedia
    You can set this up in fstab with a syntax change to have this "remount" happen at boot.

    Bindfs creates an immutable "view" of something with a set of permissions that may differ from the source.
    Last edited by Morbius1; June 13th, 2021 at 03:11 PM.

  3. #13
    Join Date
    Jun 2019
    Location
    Dirndl-land
    Beans
    874
    Distro
    Lubuntu 20.04 Focal Fossa

    Re: umask, file copy, file creation, directory creation - I'm confused, please help

    OK, Thanks.
    I'm in over my head here.
    Binding and so on is out.
    My file system is ext4, I've read through the complete "man mount" and am none the wiser.

    I'll just stick to manually changing the permissions on copied files. But I thought it would be simpler.

  4. #14
    Join Date
    Mar 2010
    Location
    Squidbilly-Land
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: umask, file copy, file creation, directory creation - I'm confused, please help

    If the file system is ext4, that is a POSIX file system and normal chown, chmod, chgrp commands all work in the expected hierarchy and umask works as expected .. unless you use a GUI tool. If you do, then you'll need to make the changes to the logins.def file.

    If you do file management in a shell, then all works as expected. Avoid the GUI. That's my rule. The GUI just makes simple things complex.

  5. #15
    Join Date
    Dec 2009
    Beans
    6,556

    Re: umask, file copy, file creation, directory creation - I'm confused, please help

    Quote Originally Posted by ml9104 View Post
    OK, Thanks.
    I'm in over my head here.
    Binding and so on is out.
    My file system is ext4, I've read through the complete "man mount" and am none the wiser.

    I'll just stick to manually changing the permissions on copied files. But I thought it would be simpler.
    My mistake. I thought this ...
    External storage can be anything, but mostly files from FAT/NTFS systems.
    ... meant that for any random usb storage device you attach to your system you want to see a specific set of permissions.

  6. #16
    Join Date
    Jun 2019
    Location
    Dirndl-land
    Beans
    874
    Distro
    Lubuntu 20.04 Focal Fossa

    Re: umask, file copy, file creation, directory creation - I'm confused, please help

    Quote Originally Posted by Morbius1 View Post
    My mistake. I thought this ...

    ... meant that for any random usb storage device you attach to your system you want to see a specific set of permissions.
    Yes, sorry. The whole thing got a bit involved with different file systems, POSIX etc.

    My goal was to:

    1: Have newly created files and directories in $HOME have certain permissions, in my case no "other" rights. This works perfectly after modifying /etc/login.defs

    2: When copying files into my $HOME I want those permissions set as well. This does not work. Either the existing permissions are kept (when copying from a Linux file system into $HOME), or random (it seems) permissions are applied when copying from FAT/NTFS/Web/etc. into $HOME.

    This is where I thought a simple solution is possible. But apparently not.

  7. #17
    Join Date
    Mar 2010
    Location
    Squidbilly-Land
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: umask, file copy, file creation, directory creation - I'm confused, please help

    umask only applies when a file is created. When I file is copied, the permissions from the original are copied too. It is a feature.

    If you don't want "other" to have any read or write, just set the permissions that way. There are recursive options for most of those commands (be extremely cautious doing this) or if those are too blunt, use 'find' to be more selective about the file system objects to change the permissions on. Don't forget that creating a script to create a script is perfectly valid for caution too.

  8. #18
    Join Date
    Jun 2019
    Location
    Dirndl-land
    Beans
    874
    Distro
    Lubuntu 20.04 Focal Fossa

    Re: umask, file copy, file creation, directory creation - I'm confused, please help

    Quote Originally Posted by TheFu View Post
    umask only applies when a file is created. When I file is copied, the permissions from the original are copied too. It is a feature.
    too.
    @TheFu:

    Thank You!
    That was a clear answer that confirms my findings.
    It seems I'm not an idiot after all.

    I'll handle copied files manually.

    Thank You all, this is from my point of view solved.

  9. #19
    Join Date
    Mar 2010
    Location
    Squidbilly-Land
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: umask, file copy, file creation, directory creation - I'm confused, please help

    Quote Originally Posted by ml9104 View Post
    @TheFu:

    Thank You!
    That was a clear answer that confirms my findings.
    It seems I'm not an idiot after all.

    I'll handle copied files manually.

    Thank You all, this is from my point of view solved.
    It only applies to file systems that support the POSIX standards - i.e. not NTFS, not exFAT, not FAT32. I don't know what happens with HPFS+.
    Should work as expected for ext2/3/4 Reiserfs, zfs, btrfs, f2fs, and the 20 other non-Windows file systems with kernel support in Linux. It also works in NFS for mounts that aren't read-only.

Page 2 of 2 FirstFirst 12

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •