That was a “fun” debugging session…

  • HiddenLayer555@lemmy.ml
    link
    fedilink
    English
    arrow-up
    8
    ·
    edit-2
    8 hours ago

    Worse, it preserves “special” files like the ones in /dev or /var which aren’t removable by anyone other than root. Love extracting a system file backup in my file server as a regular user in order to get just a few files out of it, and promptly not being able to fully delete it afterward without SSHing into the server and using sudo.

    I don’t get how a regular user can even create files like that. Sounds like a security vulnerability.

  • IsoKiero@sopuli.xyz
    link
    fedilink
    English
    arrow-up
    14
    ·
    edit-2
    15 hours ago

    Since no one has yet mentioned, by default if you’re running tar as a non-root user it extracts files with owner/umask of the current user and if you run it as root (or superuser) it’ll preserve ownership and permissions. From tar man page:

    –no-same-owner

    Extract files as yourself (default for ordinary users).

    –no-same-permissions

    Apply the user’s umask when extracting permissions from the archive (default for ordinary users).

    As mentioned, with root the defaults are to keep UID/permissions as they are in the archive. (–preserve-permissions and --same-owner).

  • tetris11@lemmy.ml
    link
    fedilink
    arrow-up
    23
    ·
    edit-2
    20 hours ago

    Just bear in mind that uid 1001 on one machine is not generally uid 1001 on another, and that if you copy the tar off machine you’re more than likely giving permission to somebody other than the intended target

    • esa@discuss.tchncs.de
      link
      fedilink
      arrow-up
      11
      ·
      18 hours ago

      It’s even a tape archiving tool. Just pretty much nobody uses it in the original way any more.

      Very much one of those “if it ain’t broke, don’t replace it” tools.

      • ReversalHatchery@beehaw.org
        link
        fedilink
        arrow-up
        1
        ·
        16 hours ago

        but also the way it puts file data one after the other can be beneficial for compression, especially if you can define the order of the files somehow

    • lorty@lemmy.mlOP
      link
      fedilink
      arrow-up
      3
      ·
      19 hours ago

      I just assumed that whenever it would be expanded that the contents would have the default permissions for that user.

      It’s actually a cool feature I just feel dumb for how long it took me to realize this was the issue.

    • ki9@lemmy.gf4.pw
      link
      fedilink
      English
      arrow-up
      1
      ·
      8 hours ago

      Well having the wrong permissions in system files will mess up your system. So when you restore from backup and want the backed-up permissions too.

  • monovergent@lemmy.ml
    link
    fedilink
    arrow-up
    13
    arrow-down
    1
    ·
    1 day ago

    Learned to make use of this the hard way when transferring a directory over a FAT32 USB drive messed up the permissions.

    • ki9@lemmy.gf4.pw
      link
      fedilink
      English
      arrow-up
      2
      ·
      8 hours ago

      I uses to use 7z for my archives but it dropped the permissions. Now I tar it first into a .tar.7z aka .t7z when I want maximum compression.