LWN.net Logo

Advertisement

E-Commerce & credit card processing - the Open Source way!

Advertise here

How to create a command-line password locker (Linux.com)

How to create a command-line password locker (Linux.com)

Posted Mar 17, 2007 2:49 UTC (Sat) by terminator (guest, #2292)
Parent article: How to create a command-line password locker (Linux.com)

I use vim with the following config in ~/.vimrc

" Use GnuPG to open a .gpg file
augroup gpg
au!
au BufReadPre,FileReadPre *.gpg set viminfo=
au BufReadPre,FileReadPre *.gpg set noswapfile
au BufReadPost *.gpg :%!gpg -q -d
au BufReadPost *.gpg | redraw
au BufWritePre *.gpg :%!gpg --default-recipient-self -q -e -a
au BufWritePost *.gpg u
au VimLeave *.gpg :!clear
augroup END

Whenever I open a .gpg file, vim ask for my gpg key. It's pretty straightforward.


(Log in to post comments)

How to create a command-line password locker (Linux.com)

Posted Mar 17, 2007 8:39 UTC (Sat) by DG (subscriber, #16978) [Link]

Thanks! I've been using gpg through two scripts on the command line, but always view the file with vim.... this will make life much better :-)

How to create a command-line password locker (Linux.com)

Posted Mar 18, 2007 18:09 UTC (Sun) by cortana (subscriber, #24596) [Link]

There are a couple of scripts on the Vim website to do this too. The one I used is at: http://vim.sourceforge.net/scripts/script.php?script_id=661

How to create a command-line password locker (Linux.com)

Posted Mar 19, 2007 12:29 UTC (Mon) by sitaram (subscriber, #5959) [Link]

bufreadpre doesn't work for a file that doesn't exist. So when creating a *new* password file you should create it, save&close it with a blank line or something, then edit again. I.e., on the first edit of a new file, the 2 critical settings don't "take".

Also understand that if you hit Ctrl-C on the password prompt at a bad point when using :x or :wq instead of a :w, your entire file is gone :-(

Get into the habit of using :w, *then* :q. And make backups -- heck it's an encrypted file so make many of them :-)

Finally, for those of you (like me) who don't really use GPG (yeah, I know, bad net citizen and all that...) and prefer a symmetric encryption, use these commands in place of the !gpg commands above:

for BufReadPost: use "openssl bf -d -a"
for BufWritePre: use "openssl bf -salt -a"

Copyright © 2010, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds