How To Use VIM Editor To Encrypt/Decrypt and Password Protect Files In Linux

As of now, we have wrote many articles to encrypt/decrypt files and folders in Linux with varies utility. Today also, we are going to cover the same topic with help of native Linux text editor called VIM.

Encryption is the process of encoding files using standard encryption algorithm which allows only authorized user to view.

When you are looking for a single file privacy which contains like various password, login details, personal information, or etc,., vim is the best suitable option for you to protect file.

What’s VIM

Vim is a programmers text editor that is upwards compatible to Vi. It can be used to edit all kinds of plain text. It is especially useful for editing programs. There are a lot of enhancements available in Vi like multi level undo, multi windows and buffers, syntax highlighting, command line editing, filename completion, on-line help, visual selection, etc..

Suggested Read :
(#) Cryptkeeper – An Easy Way To Encrypt And Decrypt Folder or Directory In Linux
(#) GnuPG – An Easy Way To Encrypt/Decrypt Files From Command Line in Linux
(#) SiriKali – GUI Front End To Manage ecryptfs, cryfs, gocryptfs, securefs, and encfs Encrypted Folders
(#) Gnome Encfs Manager – An Ease way to Create a Encrypted Directory in Linux
(#) Steghide – An Easy way to Hide Confidential Data Inside Images and Sound Objects in Linux
(#) Cipher – Two Simple Commands To Encrypt/Decrypt Files and Directories In Linux Command Line

How to Install vim in Linux

Vim is available in the repositories of most major distributions. So, use your distribution package manager to get installed.

For Debian based systems, use apt-get or apt package manager to install vim.

$ sudo apt-get install vim

For RHEL/CentOS based systems, use yum package manager to install vim.

$ sudo yum install vim-enhanced

For Fedora system, use dnf package manager to install vim.

$ sudo dnf install vim-enhanced

For openSUSE system, use zypper package manager to install pass.

$ sudo zypper in vim

For Arch Linux based systems, use pacman package manager to install vim.

$ sudo pacman -S vim

How To Use Vim to encrypt/Decrypt Files

Open a new file though vim with -x option followed by file name, it will ask you to enter the password twice to open a given file name with the encrypted text document. Make sure you have to remember the password to open the document.

# vim -x test.txt



Warning: Using a weak encryption method; see :help 'cm'
Enter encryption key: *********
Enter same key again: *********

After inputting the password twice, vim open the encrypted text document and allow users to insert contents after hitting i or Insert key. Type whatever you want then hit Esc + :wq or Esc + ZZ to save and quit vim.

File encryption through VIM editor.
~
~
~
~

When you try to open a encrypted file with any text editor or file view commands will endup with errors, through a VimCrypt message.

# more test.txt
ÏvmCrypt~01!"GìVéûÎö0öÿ
©ìÞh£Âzà >

This can be accessible only through vi/vim. To open an encrypted file, just use the same syntax like vi/vim followed by fine name. It will ask you to enter the password to open the file.

# vim test.txt




Need encryption key for "test.txt"
Warning: Using a weak encryption method; see :help 'cm'
Enter encryption key: *********

Now, we can able to see the file contents.

File encryption through VIM editor.
~
~
~
~
~
~
"test.txt" [crypted] 1L, 36C                                                                                                

1,1           All

You may also like...

Shares
Close
Please support the site
By clicking any of these buttons you help our site to get better