Tag Archives: linux howto

Encrypt/Decrypt File with Vim Editor

In this howto we will see how to encrypt and decrypt a file with Vim editor.

Lets Encrypt a file:

linux-06ac:/opt # vim -x encryptedfile.txt
Warning: Using a weak encryption method; see :help 'cm'
Press ENTER or type command to continue

Now Press enter and it will ask you to set a password.

Enter encryption key: **********
Enter same key again: **********

Once you setup the password, you will be presented with the blank page where  you can start writing to the file as you do with Vim.

I am writing ” Helo Linux World” as an example to my encryptedfile.txt , save and quit with :wq

Not cat the file

linux-06ac:/opt # cat encryptedfile.txt 
VimCrypt~01!q"[�HY�&!���+B]3linux-06ac:/opt #

We can see that the file is Encrypted.

 

Decrypt the File:

To Decrypt permanently, open the file as following:

linux-06ac:/opt # vim encryptedfile.txt

Give the password to the file , you set while encrypting it.

Then type :X and press enter twice (without typing anything) when asked for “Enter encryption key:”

Now save and exit with :wq and viola the file is decrypted.

linux-06ac:/opt # cat encryptedfile.txt 
Helo Linux World

Thanks & Regards,

Salman A. Francis

YouTube: YouTube.com/Linuxking
Twitter: linuxking77
Facebook: https://www.facebook.com/groups/LZHProject/

Linux Tips ( grep the text without hashes and blank lines )

In our second post of linux tips i would like to share a very simple example in which i will use grep tool to remove all the hashes and blank lines from a file.

In our example we will use file1.txt with the following content

linux-11oz:/test # cat file.txt 
#The file with hashes
###
####
##

This is a test file

With lots of spaces


and few lines with


####hashes
###

So lets remove the hashes and blank lines with single grep command

We can use the following trick

linux-11oz:/test # grep . file.txt | grep -v "#"
This is a test file
With lots of spaces
and few lines with

The “.” will remove the blank lines and  “-v” will invert the match of #

Thats how simple it is. If you know a better way of doing it , Please send me an email or comment.

Email: learning@itpings.com

Thanks

Salman A. Francis