How To Password Protect a VIM Text File in Ubuntu

One of the most complete and useful text editors for Linux environments is VIM (VI IMPROVED), and this is present in any used Linux distro.

When we work with files on the computer, it is essential that we take into account that the security and protection of them are critical to keeping all the information stored in them safely.

One of the features that most attracts attention is the possibility of creating encrypted text files using various secure encryption methods.

Today I will teach you how to perform this process using VIM.

Installation of VIM

In case of having VIM still active in our distro we proceed to its installation executing the following line according to the distro to be used:

sudo apt install vim ( Debian and Ubuntu )

sudo yum install vim ( RedHat and CentOS )

sudo dnf install vim ( Fedora )

Encryption of Text Files using VIM

To protect our text files using VIM we must use the -x parameter, for this, we will use the following syntax.

vim -x file.txt

In this case, we will create a file called TheLinuxCode.txt.

When pressing Enter we will see that it will be necessary to enter an access password for the file and it must be confirmed:


If the passwords match we can access the file for editing:

Once the editing process is finished, press the Esc key and then: wq to write and save the changes in the text file.

In this way when we use the syntax vim file.txt to access the file will be necessary to enter a password for access to it.

As we have verified establishing a security mechanism in text files using VIM is simple and practical in any Linux distro.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *