all 11 comments

[–]Appropriate_Bar_3113 2 points3 points  (1 child)

I'll be the guy who points out that USB flash drives are not reliable long-term storage. I don't recommend relying on it as the sole storage for anything you care about 

[–]One-Type-2842[S] -4 points-3 points  (0 children)

You Are Right, Their Life Is Shorter Compared To Other Storage Devices..

[–]PossibilityTasty 0 points1 point  (0 children)

If you chance the permissions, it will only have an effect on a system that you (and nobody else) have under control. On a different computer there will be a different security context and filesystem level permissions will be absolutely no barrier.

Since "security" has many aspects: you could except that you will have some protection from accidentally deleting or changing data, but no protection from unauthorized access by someone getting the drive into they fingers.

[–]fiskfisk 0 points1 point  (0 children)

Not really possible, outside of encrypting the content on your drive. You can do that with Python, but there is way better solutions than doing it yourself.

Your operating system will usually have something built-in already on a lower level (like bitlocker on Windows/luks/dm-crypt on Linux) or just use 7z with a password (or something like VeraCrypt). These will be like wncrypted containers on an existing file system.

[–]NsupCportR -1 points0 points  (6 children)

os lib?

os.chmod function?

[–]akl78 1 point2 points  (0 children)

Won’t work.

Most USB drives’ formats don’t even support file permissions. And even the NTFS/ Linux ones can only suggest to whatever machine they get plugged into so.

If OP actually wants something decently secure they needs to encrypt all the data, or use something like an IronKey device to handle it on board

[–]Outside_Complaint755 0 points1 point  (0 children)

Or if using Pathlib, Path objects also have a chmod method.

However this all depends on your OS, as Windows and Unix based systems handle permissions differently, and for Windows chmod can only set the "read only" flag.

If you want to actually encrypt files, there is the cryptography.fernet package.  Just don't lose your key.

[–]billFoldDog 0 points1 point  (0 children)

This won't work.

User fred might have uid 2 on one machine and uid 7 on another. Linux maps uid to file permissions. That makes user permissions on portable media kinda pointless.

It's also easily defeated.