Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Vim to protect files with password in Linux

2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

Editor to share with you how to use Vim to protect files in Linux, I believe most people do not know much about it, so share this article for your reference. I hope you will gain a lot after reading this article. Let's learn about it together.

Vim is a popular, feature-rich and highly extensible Linux text editor. One of its special functions is to support various encryption methods with passwords to encrypt text files.

To install the full version of Vim, simply run these commands:

$sudo apt install vim # Debian/Ubuntu system $sudo yum install vim # RHEL/CentOS system $sudo dnf install vim # Fedora 22 +

See: ten years later, Vim 8.0 was released-install on Linux

How to use Vim to protect files with password in Linux

Vim has a-x option that allows you to use it to encrypt files when you create them. Once you run the following vim command, you will be prompted to enter a key:

$vim-x file.txt warning: weak encryption method is being used; see: help 'cm' enter encryption key: * enter the same key again: *

If the key entered the second time is correct, you can modify this file.

Password-protected Vim files

After you have modified it, press Esc and type: wq to save and close the file. The next time you want to open it and edit it, you have to enter the key like this:

$vim file.txt requires encryption key for "file.txt" warning: weak encryption method is being used; see: help 'cm' input key: *

Suppose you type a wrong password (or no password) and you will see some junk characters.

Encrypted content in Vim

Set up a strong encryption method in Vim

Note: the warning indicates that the file is protected by a weak encryption method. So next, let's look at how to set up a strong encryption method in Vim.

Weak encryption of Vim Chinese text

To view the encryption method (cm) set, type:

: help 'cm'

Sample output:

* 'cryptmethod'* *' cm'* thod' string (default "zip") global or local to buffer | global-local | {not in Vi} encryption method used when the buffer is written to the file: * pkzip* zip PkZip compatible method. A weak encryption method. Backward compatibility with Vim 7.2 and older. * blowfish* blowfish puffer fish encryption. The intermediate strength encryption method has some defects in implementation. Vim 7.3or above is required, and files encrypted with it cannot be read by Vim 7.2or older. It adds a "seed", which is different every time you write to a file.

You can set a new encryption method for a Vim file as shown below (in this case we use the blowfish3 encryption method)

: setlocal cm=blowfish3

Then type enter and: wq to save the file.

Set strong encryption to Vim files

Now you should not see that warning message when you open the file below.

$vim file.txt requires the encryption key of "file.txt" to enter the encryption key: *

You can also set the password after opening the Vim file, and use the: X command to set an encrypted password as shown above.

The above is all the contents of this article entitled "how to use Vim to protect files in Linux". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report