I would like to use a MSDOS formatted USB disk to be able to safely transfer data between them. Therefore I want to decrypt and encrypt easily all files in a folder (and sub folders), possibly with a python script or a bash command.

  • I do not want to encrypt the entire USB stick, as this is probably not possible when formatted with MSDOS.
  • I cannot use a Linux/MacOS format, as I want to be able to use the USB stick with both of them.
  • I want to have a single line command to encrypt all files in the folder and subfolder by supplying a password!
  • I want to have a single line command to decrypt all of these files by giving the right password.
  • It should be done quickly (for about 1000 files)

Is there some way to do this easily? Is there a python tool? Or a Linux command?

  • 1
    You really need to Stop demanding & Start Exploring. Explore your options. Show us How you have approached for the solution, What you have done yet and Where exactly you need help. That way you would get much better responses. – C0deDaedalus Jul 29 '18 at 16:11
  • Yes so good answer. I demand to shut down wikipedia and stackoverflow and all instances of where to find information. Everyone should explore themselves from scratch. Yes, what a good advice... – Alex Jul 30 '18 at 5:25
  • 1
    Superuser is not a paid service site where you can just ask people "I want this" and "I want that" and they will simply do it for you. You have to try for yourself first, then if you hit a point where you can't figure out how to do a certain part, you (first search to see if someone already answered your question, then) ask a question specifying what you're trying to do and where you are stuck at so that people can help you. I apologise but It had to be this way, otherwise you won't get better answers. – C0deDaedalus Jul 30 '18 at 6:28
  • 1
    First, did you compare the filesystems that macos can write to the ones linux can write? I'm sure there's more than just msdos/vfat this milennium. And you know decrypting & writing the plaintext files to any drive is a security risk, deleting files does nothing to really erase them & ssd's are virtually impossible to guarantee wiping a file, even regular hd's can't always wipe a file, then there's disk cashes & program's temp files. Opposed to on-the-fly encryption? – Xen2050 Jul 30 '18 at 8:11

Here are some possible solutions.

Judging from your question, I assume that you are not very well versed in encryption and are only trying to protect your data from prying eyes while it is on transit (USB stick) between the two machines, and that you are not dealing with extremely sensitive data (like when some people's lives depend on its secrecy).

You could pack your data into a tarball and encrypt it with GnuPG.

$ tar -cvf archive.tar directory_with_data
$ gpg --symmetric archive.tar

You will be prompted for a passphrase and the encrypted file archive.tar.gpg will be generated. On the other end, do

$ gpg --decrypt archive.tar.gpg > archive.tar
$ tar -xvf archive.tar

to decrypt and unpack.

This is a very quick and dirty solution that does not scale very well. A more robust solution is to use EncFS.

Create or mount an ecrypted directory on the USB stick.

 $ encfs path_USB/.encrypted_directory path_machine/transparent_directory

Now when you put your files in transparent_directory they would be encrypted on-the-fly onto .encrypted_directory. To unmount the transparent_directory

 $ fusermount -u path_to_transparent_directory

The paths in the commands above must be complete paths (never relative paths).

The EncFS approach is more convenient and scales better than the previous one. However, notice that someone with access to the encrypted data would know how many files are in the directory and, depending on her/his resources, can also deduce the size of the files as well as the length of the filenames. Confirmation attacks can also be performed on the filenames themselves.

|improve this answer|||||

I actually came across something that does what I want. And instead of writing nonsense or nothing, I want to share it so it might help someone else.

The tool is in github: https://github.com/jlinoff/lock_files

Its a single(!) python script that can be used to encrypt, for example, all files inside a directory (recursively). The command would be

python lock_files.py -r --lock myfiles/

and to decrypt the files you use

python lock_files.py -r --unlock myfiles/

In that simple case you are asked to provide the password on the command line. I store the folder with the files AND the github repo on the USB stick so I can use it on whatever computer I use (given python is installed and maybe some required packages). It also is reasonably fast...

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.