How to create in linux a password protected file so it ask for the password every time the user wants to open it in linux or windows computers.

This process must be done in linux command line but the files could be open in linux or windows computers so the protection must run in both O.S.

EDIT for Ramhound

I tried this:

7za a -tzip -pPASSWORD -mem=AES256 file.zip file.txt

This is a CROSS-PLATFORM way while the file could be unzip in any O.S.

But I must not use a compression way.

vim +x file.txt

This encrypts but only ask for the password when I open it with vim not with notepad(sorry if this is fool but I'm putting my attempts)

gpg -c file.txt

This creates a new file with '.gpg' extension but, such as zip, for this I need a specific SW

  • What you want does not exist. – Ramhound Aug 12 '14 at 16:03
  • So because you don't have the knowledge of how to do this you downvote my question? – tachomi Aug 12 '14 at 16:05
  • I actually downvoted a software recomendation question which is specifically not on topic here at Superuser. You want a cross-platform feature that simply does not exist. You also basically threw out any solutions dealing with creating an password protected archive file. When you ask a good question I will be the first to upvote it. – Ramhound Aug 12 '14 at 16:07
  • 1
    Ok you now can see the possible solutions I tried ... by the way, I'm not asking for a specific SW, I'm asking for a specific WAY, I guess this both are different – tachomi Aug 12 '14 at 16:23
  • What you want would require a cross-platform tool. There does not exist a native solution in either platform. – Ramhound Aug 12 '14 at 16:39

Use a password protected 7z or Zip file. It will work on any OS that can handle them. I personally prefer 7z.

  • The thing is that this must run with a simple opening, I know about 7z - 7za but this will compress the file & I'm not looking for a compression way... by the way I prefer 7z too – tachomi Aug 12 '14 at 15:52
  • For 7z, you could skip the compression using -m0, and just use the password functionality. – ernie Aug 12 '14 at 16:05
  • @ernie when trying this I'm getting this error: System error: E_INVALIDARG – tachomi Aug 12 '14 at 16:25
  • 1
    My mistake . . . should be -mx0 – ernie Aug 12 '14 at 16:46
  • I'm making this: 7z a -mx0 -pPASSWORD file.txt but it makes a '.7z' extension :( – tachomi Aug 12 '14 at 17:01

It can be done, albeit in a quite ugly way.

You'd need to write an encryption script that reads the plaintext file, pipes it to some symmetrical-encryption providing the password too (eg. using openssl des3).
Then, it writes a binary. The binary, which contains an encoded version of the encrypted file, passes the aforementioned file to the decrypter binary, and opens the resulting file.

However, the solution above is rather inelegant. A much simpler approach would be using password protected archives; why don't you want to use them?

  • That's what I'm looking for, without being compressed or either encrypted, only pretect a simple .txt file with a password but it must work either in windows or linux ... But I think... as @Ramhound says.... This could not be possible to do for both platforms – tachomi Aug 12 '14 at 17:11
  • This just encrypts the file. If you want that just use Truecrypt. – Ramhound Aug 12 '14 at 17:14
  • @Ramhound: OP explicitly asked for the file to open by double clicking. My solution satisfies this requirement, whereas simply using Truecrypt doesn't. – Giulio Muscarello Aug 12 '14 at 19:46
  • @tachomi don't accept what that ramhound guy says when he says things are impossible, he always says things are impossible when others can do it. It looks like you might be able to do 7z without compression I know it was possible for pkzip.. here with 7zip superuser.com/questions/336243/… the second answer says -m0=Copy – barlop Oct 13 '14 at 22:37

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.