Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So I created a gpg encrypted file with password:

gpg -c passwords.txt.gpg

how can I open it with vi, edit it, then close it? (So that no passwords.txt file will be created, the decrypted passwords.txt is only in the memory! - better: after closing the passwords.txt.gpg file, the memory should be cleaned, so it shouldn't contain unencrypted passwords).

share|improve this question
    
You may be looking for a password manager such as keepass. It has command line functionality, and a GUI. – jordanm Aug 28 '12 at 15:04
up vote 8 down vote accepted

Original Answer

The gnupg plugin for Vim does this:

This script implements transparent editing of gpg encrypted files. The filename must have a ".gpg", ".pgp" or ".asc" suffix. When opening such a file the content is decrypted, when opening a new file the script will ask for the recipients of the encrypted file. The file content will be encrypted to all recipients before it is written. The script turns off viminfo and swapfile to increase security.

EDIT #1

As of 2016-07-02, the original gnupg plugin is now no longer being maintained:

Due to the lack of time I'm not able to continue the development of this script. James McCoy took over development. New versions can be found at vimscript #3645.

There is however a new version:

share|improve this answer
    
works, thank you! – gasko peter Aug 31 '12 at 17:50

If you truly mean a gpg file, then the gnupg plugin as mentioned is your best option.

If you mean "how can I open, edit, and save an encrypted file with vim" then you might also explore the -x option. It will allow you to enter a password and then save the file in an encrypted form, and does the right thing in terms of encrypting the .swp file as well.

See: http://vimdoc.sourceforge.net/htmldoc/editing.html#encryption

Be advised:

  1. the cm=blowfish option is vital, otherwise you're saving with very weak crypto
  2. I don't know if vim scrubs the memory before exit

Also, I don't know if keepass (mentioned above) as a command-line counterpart for Linux, but PasswordSafe (available for Windows and Linux) does: http://nsd.dyndns.org/pwsafe/ It allows you to edit entries in the shell, though if you want more freeform notes, full-screen editing, etc. you'd want something vi-friendly.

share|improve this answer

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.