For security reasons, some important files are usually encrypted or encrypted, and the following is a brief introduction to the file encryption method under Linux:
One, zip encryption
1) file encryption
Use the command "zip-e filename.zip filename" To enter the password prompt, enter the password 2 times. This file is encrypted when you need a password to extract
The following begins to encrypt the test.txt file [[email protected] ~]# cat Test.txt this is a test!!! [[email protected] ~]# zip-e test.txt.zip test.txt //The following encryption operation, you need to enter the password two times enter password: Verify password: Adding:test.txt (stored 0) [[email protected] ~]# lstest.txt test.txt.zip for decompression, you need to enter the password [[email protected] ~]# rm-f Test.txt[[email protected] ~]# unzip Test.txt.zip Archive: test.txt.zip[test.txt.zip] test.txt password: Extracting:test.txt [[email protected] ~]# cat test.txtthis is a test!!!
2) Folder encryption
Use the command "zip-re dirname.zip dirname" To enter the password prompt, enter the password 2 times. This file is encrypted when the decompression is required password.
below begins to encrypt the directory [[email protected] ~]# mkdir dirtest[[email protected] ~ ]# Cat Dirtest/haha.txt This is test of DIR!!! [[email protected] ~]# zip-re dirtest.zip dirtestenter password:verify password:adding:dirtest/(stored 0) ad Ding:dirtest/haha.txt (stored 0%) need to enter password when extracting directory [[email protected] ~]# rm-rf dirtest[[email protected] ~]# Unzip Dirtest.zip Archive:dirtest.zip Creating:dirtest/[dirtest.zip] Dirtest/haha.txt password:extracting:dirtest/ Haha.txt [[email protected] ~]# ls dirtesthaha.txt[[email protected] ~]# cat Dirtest/haha.txt This is TES T of dir!!!
II, GNUPG encryption
GnuPG's full name is GNU Privacy Protection (GNU Privacy Guard), often referred to as GPG, which combines a set of cryptographic software. It was written in the C programming language by the GNU project. The latest stable version is 2.0.27. In most Linux distributions today, the GNUPG package is shipped by default, so in case it isn't installed, you can use apt or yum to install it from the repository (yum install gnupg). Note: GPG can only encrypt the file, and the directory will not complete encryption!
The following begins to encrypt the Test.txt file using the GnuPG method [[email protected] ~]# cat Test.txt this is a test!!! [[email protected] ~]# gpg-c test.txt can ' t connect to '/root/.gnupg/s.gpg-agent ': No such file or directory This information can be ignored note: As on the encryption, the paraphrase will be asked to enter two password, the specific file encryption. Once you run the GPC command with the-C option (fully encrypted with the symmetric cipher algorithm), it generates a file. gpg file. [[email protected] ~]# ll Test.txt*-rw-r--r--. 1 root root 4 10:08 test.txt-rw-r--r--. 1 root root 4 10:04 test.txt.gpg The file is encrypted, it is best to delete the source file! Don't keep the source files anymore! [[email protected] ~]# rm-f test.txt file decryption operation. Note When the paraphrase prompt appears, you need to provide the same password that you entered when encrypting to decrypt [[email protected] ~]# gpg test.txt.gpg gpg:3des encrypted Datacan ' t Connect to '/root/.gnupg/s.gpg-agent ': No such file or directorygpg:encrypted with 1 passphrasegpg:WARNING:message was Not integrity Protected[[email protected] ~]# ll Test.txt*-rw-r--r--. 1 root root 4 10:08 test.txt-rw-r--r--. 1 root root 4 Jan 10:04 test.txt.gpg[[email protected] ~]# cat test.txtthis is a test!!!
File encryption operation record under Linux