Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I would like to set up a couple of bash scripts to encrypt and decrypt a master text file containing passwords for banking, work, etc. for the purpose of editing it and displaying the entries when I need to look something up. I would prefer to use as few third-party sources as possible, and have a possible solution (?) using just a standard terminal:

  1. openssl
  2. text editor of choice
  3. shred

My question is, can anyone provide a reason why this is not a good idea, from a security point of view? By that I mean I would like to avoid losing those passwords to casual hacking attempts (I give up if the NSA comes a-knocking).

Let me explain in more detail. I have 3 bash scripts listed below, in which $PFILE is a path variable pointing to the directory containing of the password file, and passfile.enc is the encrypted file (the names of the victims have been changed to protect their identity).

  1. mypasswds.open: opens a predetermined password file encrypted using AES 256-bit encryption via openssl. It opens the file externally in, e.g., gedit, so I can easily modify the entries save the updated file.

    #!/bin/bash
    openssl aes-256-cbc -d -in $PFILE/passfile.enc -out $PFILE/passfile.tmp
    gedit $PFILE/passfile.tmp &
    
  2. mypasswds.close: closes, i.e., re-encrypts the file once I am done editing it, and removes the decrypted text file.

    #!/bin/bash
    openssl aes-256-cbc -in $PFILE/passfile.tmp -out $PFILE/passfile.enc
    shred --remove $PFILE/passfile.tmp
    
  3. mypasswds.display: writes the output of passfile.enc to the terminal window, and then immediately removes the decrypted file. The idea would be to look at the terminal output to recall the password, and then close it immediately after.

    #!/bin/bash
    openssl aes-256-cbc -d -in $PFILE/passfile.enc -out $PFILE/passfile.tmp
    cat $PFILE/passfile.tmp
    shred --remove $PFILE/passfile.tmp
    

For example, if I want to add a new password entry to the file, I run mypasswds.open and enter my (randomly-generated and painstakingly memorized) master password. The text file opens in, for example, gedit and I update it. I then save and close the editor, and run mypasswds.close to re-encrypt and remove the temporary, unencrypted file.

If I just want to look something up, I run mypasswds.display, look at the output to the terminal to refresh my memory, and immediately close the terminal window.

Questions / doubts that come to mind:

  1. Does terminal output get stored somewhere upon closing the terminal window? Or is gone forever?
  2. Is shred --remove a secure option for completely destroying the temporary text file?
  3. If someone were to obtain the encrypted file, is it possible to decipher, and with what amount of effort?

If this whole idea is for the birds (why?), that is valuable information too!

Thanks in advance.

share|improve this question
add comment

1 Answer 1

up vote 2 down vote accepted

First of all: be aware that anyone with root and / or physical access to your system will be able to intercept any passwords that you type. And there is hardly anything you can do about it. Physical access means root, and root means low level access to hardware.

Also, if someone is a user on your system, then he or she is already in your "inner circle", since it is much easier to escalate privileges (gain root permissions) than to log in to a random system.

Personally, I use a similar system, but I don't keep there any information that would cost me my life's savings or professional reputation -- rather something like my askubuntu password. Also, I implement a bit of primitive, but not obvious encryption (like, omitting a common suffix of all the passwords, replacing certain words or numbers by other words or numbers, or not storing the information that I'm sure I remember and which is crucial, like the name of the service that a certain password refers to etc.).

As for shreeding in case of the mypasswd.display command -- why are you creating a temporary file? Why not omit the "-out" option and just send it directly to stdout?

Finally, I have a comic for you: brought to you by XKCD

share|improve this answer
    
Thanks for the reply, definitely some good suggestions there. I'm only using this system on a personal laptop and on a home server not connected to the outside world. I'm the only person with root or physical access to either, so it seems fairly secure from that point of view (?). As for shredding in the display script, your point is well taken; there is no reason to write to a temporary file in this case. –  Dave B. Jun 26 '13 at 18:23
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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