Encryption and decryption of files and directories
1. File encryption and decryption:
# openssl des-salt-in file-out file.des
# openssl des-d-salt-in file.des-out file
That file can be an archive file (tar archive).
two。 Catalogue
Archive and encrypt the entire directory
# tar-cf-directory | openssl des-salt-out directory.tar.des # encryption
# openssl des-d-salt-in directory.tar.des | tar-x # decryption
Compress the archive and encrypt the entire directory
# tar-zcf-directory | openssl des-salt-out directory.tar.gz.des # encryption
# openssl des-d-salt-in directory.tar.gz.des | tar-xz # decryption
After using-k mysecretpassword, des cancels interactive password requests. But it's very unsafe.
Use des3 instead of des for stronger encryption (Triple-DES Cipher). This also consumes more CPU.
3. Script encryption
The first method (gzexe):
This kind of encryption is not a very safe method, but it can meet the general encryption purpose and can hide the password and other information in the script.
It uses the gzexe program that comes with the system, which not only encrypts but also compresses files.
How to use it:
Gzexe file.sh
It will back up the original unencrypted files as file.sh~, and the file.sh will be turned into encrypted files.
The second method (shc):
Use shc to encrypt Linux shell scripts.
Shc is a professional tool for encrypting shell scripts. Its function is to convert the shell script into an executable binary file, which solves the problem that the script contains IP, password and so on that you don't want to disclose.
Download address of shc:
Http://www.anyside.com/linux/shc-3.8.tgz
Installation:
Tar zxvf shc-3.8.tgz
Cd shc-3.8
Make test
Make
Make test
Make strings
Make install
How to use it:
Shc-r-f script-name
After running, two files are generated, script-name.x and script-name.x.c. Script-name.x is the executable binary file after encryption; it can be run with. / script-name, and script-name.x.c is the original file that generates script-name.x (c language).