Use shc to encrypt Shell scripts to improve the security of shell script files.
Introduction: When the shell script we write contains sensitive information such as the account and password, we want to enhance the security of the script, and do not want others to view/modify your shell core code. You can use the following tools for encryption.
Shc is a script compilation tool that uses the RC4 encryption algorithm to convert shell programs into binary executable files (supports static and dynamic links ).
Shc Official Website: http://www.datsi.fi.upm.es/%7Efrosal/
Install shc
Wgethttp: // www. datsi. fi. upm. es/% 7 Efrosal/sources/shc-3.8.7.tgz
Tar vxf shc-3.8.7.tgz
Cd shc-3.8.7
Make test
Make strings
Make install
If an error is reported:
* ** Installing shc and shc.1 on/usr/local
***? Do you want to continue? Y
Install-c-s shc/usr/local/bin/
Install-c-m 644 shc.1/usr/local/man/man1/
Install: target '/usr/local/man/man1/' is not a directory: No such file or directory
Make: *** [install] Error 1
Create mkdir-p/usr/local/man/man1/and run make install
Common parameters:
-E date (specifying the expiration date)
-M message (specify the information of the expiration prompt)
-F script_name (specify the path and file name of the shell to be compiled)
-R Relax security. (It can be executed in different systems of the same operating system)
-V Verbose compilation (compilation details)
Usage:
Shc-v-f abc. sh
-V is a real encryption process.
-F followed by the file to be encrypted
Two files are generated after running:
Abc. sh. x and abc. sh. x. c
Abc. sh. x is a binary file and can be executed directly after the execution permission is granted. Change the name of mv abc. sh. x a. sh.
Abc. sh. x. c is the c source file. It is useless and can be deleted.
In addition, shc provides a method to set the validity period, such:
# Shc-e 28/01/2012-m "expired"-f abc. sh
Option "-e" specifies the expiration time, in the format of "day/month/year"; Option "-m" specifies the prompt information for executing this shell program after expiration.
If it is executed after expiration, the following prompt is displayed:
#./Abc. sh. x
./Abc. sh. x: has expired!
Expired
When using the above method, you must avoid changing the system time. You can solve this problem by adding a command to the program to automatically update the system time.
All tests have passed. Please feel free to use them!