Get the App
SLTechnology News&Howtos  ›  Servers  › 

Vi/vim comes with encryption

Shulou Source: shulou.com Published: 2022-06-03 02:15:07 10月31日 Update

Linux encrypts and decrypts files with vim/vi

First, use vim/vi encryption:

Advantages: after encryption, if you don't know the password, you can't see the plaintext, including root users.

Disadvantages: obviously let others know the encryption, it is easy for others to destroy the encrypted files, including content destruction and deletion

Vi editor I believe everyone is familiar with it, there is a command in vi to encrypt files, for example:

1) first, create an experimental file text.txt under the root home directory / root/:

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

2) enter edit mode, press ESC after typing, then enter: X (uppercase X), and enter enter

3) at this point, the system prompts you to enter your password twice, as follows:

Enter the password: *

Please enter again: *

4) exit after saving, and now this file is encrypted

5) use cat or more to view the contents of the file and show it as garbled; if you re-edit the file with vim/vi, you will be prompted for a password, and if you enter an incorrect password, it will also be displayed as garbled!

Note: after the file is encrypted, don't forget the password!

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

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

: set key=

Then enter directly, and after saving the file, the file has been decrypted.

2) or this is fine:

Use the ": X" command after opening the file correctly, and then give an empty password. Save with "wq!" Save.

The effect of the two methods is actually the same.

Tags: File encryption password input content garbled command method prompt obvious advantage example premise uppercase actual actually instruction effect plaintext mode Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Apple Microsoft macOS Linux