Well it’s time again for the Vim Tip of the Week. If you missed the previous few tips you might want to look here, here, here. Otherwise let’s get to the good stuff.

vim encryption

If you’ve been a long time reader of this blog you know I’m all about encryption. I still have a lot to learn about it, but I like to use it whenever I can. Encrypting emails. Encrypting network traffic, and with vim, encrypting documents.

From the man page:

Use encryption when writing files.  Will prompt for a crypt key.

To encrypt a document with vim open the new or existing file with:

vim -x [file]

This will prompt you for a passphrase, and only apply the encryption when writing a file.  ie; if you don’t save it or ‘w’rite the file it won’t be applied. Use any passphrase you like and the file will be encrypted to that string. Anytime you open the file after this, even using the normal open method (vim [file]) it will prompt for the password before showing any file contents.

Enjoy a bit more privacy on your machine, and easily encrypt your files with vim.

I post tutorials very regularly on this site. You may want to consider subscribing to the RSS feed. Or if you'd prefer these tips sent to your inbox you can use Email Subscriptions.

Related Posts

Random Posts

-->

Comments

9 Responses to “Vim Tip of the Week - Encryption : Aug 3, 2007”

  1. Ryan Kavanagh on August 3rd, 2007 11:09 am

    Hey, what encryption algorithm is used? DES? AES? RSA? And, any way to have it encrypt to your GPG public key?

    Great idea,
    Cheers,
    Ryan

  2. Ubuntu Tutorials on August 3rd, 2007 11:15 am

    Ryan - it uses the same encryption algo as Pkzip. If you’d like to encrypt something with your GPG you’d use a different command (outside of Vim completely):

    gpg -er [user] [file]
    which will create a new file [file].gpg
    …you’ll have to delete the original.

    to unencrypt use:
    gpg [file].gpg

    which then writes [file]

    It’s more secure using GPG, but not quite as flexible (in my opinion) as the vim encryption option.

    Isn’t it always that trade off? Powerful encryption vs ease of use.

  3. Anonymous on August 3rd, 2007 11:25 am

    The pkzip encryption was broken over a decade ago! If you want it to be “flexible”, maybe you shouldn’t use encryption at all; it will be about as secure as this!

  4. Ubuntu Tutorials on August 3rd, 2007 11:38 am

    Anonymous coward - it’s by no means supposed to be the end-all method of security. I didn’t post it as full drive encryption, unbreakable encryption or anything of the like. It is simply the built-in encryption included with vim and it *is* better than a plain text file for casual snoopers.

  5. K Lars Lohn on August 22nd, 2007 8:10 pm

    I’ve used vim -x for quite a while. I’ve just moved to a new Ubuntu 7.0.4 box after years on Suse. I was unpleasantly surprised to find that vim under Ubuntu did not have the encrypt option.

    > vi -x test.txt
    VIM - Vi IMproved 7.0 (2006 May 7, compiled May 22 2007 21:10:57)
    Unknown option argument: “-x”
    More info with: “vim -h”

    Running vim -h, indeed, showed there is no -x option. The man page, however, does list it.

    Do you have any idea what’s up with this?

  6. Ubuntu Tutorials on August 23rd, 2007 10:42 am

    @ K Lars Lohn - running “vim –version” on my machine I get the following:

    “VIM - Vi IMproved 7.1 (2007 May 12, compiled Jul 16 2007 17:22:49)”

    I wonder if you are using a previous release on a previous version of ubuntu. Perhaps try installing the vim-full package and see if that gives you any additional features

  7. K Lars Lohn on August 23rd, 2007 11:36 am

    I did:

    >sudo apt-get install vim-full
    > …
    >vim –version
    VIM - Vi IMproved 7.0 (2006 May 7, compiled May 22 2007 21:25:19)
    Included patches: 1-164, 234-235

    and now I have my precious “-x” feature back.

    The offending version of vim was installed by default in a default fresh install of Ubuntu 7.0.4. This was not an upgrade. I’m kind of at a loss in trying to figure out why they would bother to have a crippled version at all.

    Thanks for your suggestion. You got me moving again…

  8. Ra Jetley on October 24th, 2007 12:28 pm

    I used vi -x to create a encrypted file. I ftp’ed to a different machine. I am not able to open the using same passphrase. Is there a known issue ??

  9. sylesh on March 25th, 2008 3:57 am

    we can encrypt files using vim -x,but how to decrypt the same file and get back it to normal form?

Leave a Reply




    OSCON


    OSCON 2008

    Subscribe to the RSS feed!


    subscribe to the ubuntu tutorials RSS feed

    Polls


  • Regarding the Ads on Ubuntu Tutorials...

    • I dislike all web-based ads and use AdBlock (or similar) to destroy them! (49%, 155 Votes)
    • I don't mind the text-based ads on ubuntu-tutorials.com and currently view them. (31%, 99 Votes)
    • I would be willing to disable AdBlock (or similar) for this site considering I have found it helpful. (16%, 51 Votes)
    • I subscribe to ubuntu-tutorials.com via RSS or email so ads are a non-issue. (15%, 48 Votes)
    • I'd be willing to use the "Donate" button instead of see ads. (5%, 17 Votes)

    Total Voters: 316

    Loading ... Loading ...

  • Blogroll

  • Ads by Google