How Can I Secure My USB Drive with Python?

March 19, 2026 3 answers
Asked by CuriousCoder42
I recently moved a lot of my old videos and photos to a USB drive and I'm thinking about security. I'm looking for a way to restrict access to view, modify, or delete the files on my USB drive using Python. Does Python have any libraries or modules that can help me set these restrictions? If you know of any, please share. Thanks!

Answers

InfoCritic
Adjusting permissions will only protect you on devices you control. If someone plugs your USB into a different computer, those settings won't matter. So while you can prevent accidental changes, be aware that it won't stop someone from accessing your files if they get hold of the drive.
Reply to this answer
PyDevGuru
You could definitely use the `os` library! Check out the `os.chmod` function to change file permissions. If you're using Pathlib, Path objects have a `chmod` method too. Just keep in mind, the effectiveness of this varies between operating systems. For Windows, `chmod` mainly sets the 'read-only' flag. If you're looking for encryption, consider using the `cryptography.fernet` package. Just remember to keep your key safe!
Reply to this answer
SafetyFirst9
Just a heads up, relying solely on USB drives for important files isn't the best idea. They tend to have a shorter lifespan compared to other storage options.
Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions