TIL tar keeps permissions of the files and directories archived if possible.
from lorty@lemmy.ml to linux@lemmy.ml on 16 Sep 02:02
https://lemmy.ml/post/36212881

That was a “fun” debugging session…

#linux

threaded - newest

monovergent@lemmy.ml on 16 Sep 02:05 next collapse

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 on 16 Sep 20:55 collapse

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.

frongt@lemmy.zip on 16 Sep 02:10 next collapse

I’ve never heard of an archiving program that didn’t.

slock@lemmy.world on 16 Sep 06:37 next collapse

IIRC zip can, but doesn’t by default. Source : wasted 8 hours trying to figure out why something didn’t work anymore (had to switch from tar to zip because stupid security system wouldn’t let me transfer the tar file)

Zykino@programming.dev on 16 Sep 06:40 collapse

tar -czf <folder>
mv folder.{tar.gz,zip}
InnerScientist@lemmy.world on 16 Sep 10:34 collapse

Just use archive.pdf

lorty@lemmy.ml on 16 Sep 10:06 next collapse

I thought that, since users would be different between machines, there’s no point in keeping this kind of information.

TankieTanuki@hexbear.net on 16 Sep 10:29 collapse

You can sync user and daemon UIDs across machines with LDAP and SSSD.

And even if you don’t do that, keeping the information is useful when restoring to the same machine

ReversalHatchery@beehaw.org on 16 Sep 12:39 collapse

mostly anything on windows

cmnybo@discuss.tchncs.de on 16 Sep 02:25 next collapse

That’s what an archiving program is supposed to do.

vk6flab@lemmy.radio on 16 Sep 04:20 next collapse

You can even archive extended attributes with the ‘–xattrs flag.

MonkderVierte@lemmy.zip on 16 Sep 09:45 collapse

Good to know if you use xattrs as a tagging system.

Lemmchen@feddit.org on 16 Sep 08:00 next collapse

That’s a feature, not a bug. It’s an archive after all.

lorty@lemmy.ml on 16 Sep 10:04 next collapse

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.

ReversalHatchery@beehaw.org on 16 Sep 12:38 collapse

that can be done too. tarballed software normally doesn’t have permissions attached I think

syklemil@discuss.tchncs.de on 16 Sep 10:23 collapse

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 on 16 Sep 12:37 collapse

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

daggermoon@lemmy.world on 16 Sep 08:31 next collapse

Yeah I did notice that. Never really had a use for such a feature though.

ki9@lemmy.gf4.pw on 16 Sep 20:56 collapse

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.

daggermoon@lemmy.world on 16 Sep 23:08 collapse

Never thought of using .tar folders for that. Makes sense.

tetris11@lemmy.ml on 16 Sep 09:17 next collapse

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

IsoKiero@sopuli.xyz on 16 Sep 13:38 next collapse

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).

TheMadBeagle@lemmy.ml on 16 Sep 15:07 collapse

Really good callout! Thanks for adding that

HiddenLayer555@lemmy.ml on 16 Sep 20:37 collapse

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.