Use vim/vi to encrypt and decrypt files in CentOS
1. Use vim/vi encryption:
Advantage: After encryption, if you do not know the password, you will not be able to see the plaintext, including root users;
Disadvantage: it is obvious that encryption is known to others, and encryption files, including content destruction and deletion, are easily destroyed;
I believe everyone is familiar with the vi editor. There is a command in vi that encrypts files. For example:
1) Create an experiment file text.txt under the root directory/root:
[Root @ www ~] # Vim/vi text.txt
2) enter the edit mode, Press ESC after entering the content, and then enter: X (note that it is uppercase X), and press ENTER;
3) The system prompts you to enter the password twice, as shown below:
Enter the password :*******
Enter it again :*******
4) Save and exit. Now the file is encrypted;
5) Use cat or more to view the file content, which is garbled; Use vim/vi to re-edit the file and prompt you to enter the password. If the entered password is incorrect, garbled characters are also displayed!
Note: Do not forget the password after the file is encrypted!
Ii. decrypt files encrypted with vi (provided that you know the encrypted password ):
1) Use vim/vi to open a file such as text.txt. Enter the correct password and set the password to null during editing by entering the following command:
: Set key =
Press enter to save the file. The file has been decrypted.
2) Alternatively, you can:
After opening the file correctly, run the ": X" command and then give a blank password. Save and use "wq !" Save.
The two methods are actually the same.