Home  >  Article  >  System Tutorial  >  Detailed introduction to the encryption and decryption methods of Vim text in CentOS

Detailed introduction to the encryption and decryption methods of Vim text in CentOS

WBOY
WBOYforward
2023-12-31 14:49:21525browse

CentOS uses vim/vi to encrypt and decrypt files

1. Use vim/vi encryption:

Advantages: After encryption, if you don’t know the password, you can’t see the plain text, even the root user can’t see it;

Disadvantages: It is obvious that letting others know that it is encrypted will easily allow others to destroy the encrypted files, including content destruction and deletion;

I believe everyone is familiar with the vi editor. There is a command in vi that encrypts files. Here is an example:

1) First create an experimental file text.txt in the root home directory/root/:

[root@www ~]# vim/vi text.txt

2) Enter the editing mode, press ESC after entering the content, then enter: X (note the capital X), and press Enter;

3) At this time, the system prompts you to enter the password twice, as shown below:

enter password: *******

Please enter again: *******

4) Exit after saving. The file is now encrypted;

5) Use cat or more to view the file content, and it will be displayed as garbled characters; use vim/vi to re-edit the file, and you will be prompted to enter a password. If the entered password is incorrect, it will also be displayed as garbled characters!

Note: After encrypting the file, don’t forget the password!

2. Decrypt files encrypted with vi (provided you know the encrypted password):

1) Use vim/vi to open a file such as text.txt, enter the correct password, and then set the password to empty when editing by entering the following command:

:set key=

Then press Enter directly. After saving the file, the file has been decrypted.

2) Or this will work:

After opening the file correctly, use the ":X" command and then give an empty password. Save using "wq!".

The two methods actually have the same effect.

The above is the detailed content of Detailed introduction to the encryption and decryption methods of Vim text in CentOS. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:jb51.net. If there is any infringement, please contact admin@php.cn delete