How to encrypt shell script under CentOS
This article is mainly about "how to encrypt shell scripts under CentOS". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to encrypt shell scripts under CentOS.
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:
The code is as follows:
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's official website:
Http://www.datsi.fi.upm.es/~frosal/sources/
Installation:
The code is as follows:
Tar xzvf shc-3.8.6.tgz
Cd shc-3.8.6
Mkdir-p / usr/local/man/man1
This step is necessary, otherwise an error will be reported during the installation process, and shc will install the command to the / usr/local/bin/ directory; store the help documents in the / usr/local/man/man1/ directory, if there is no such directory on the system, there will be an error during installation. You can create this directory and then perform the installation.
The code is as follows:
Make install
This is to answer yes or y. Do not enter directly, or you will report an error.
How to use it:
The "- f" option specifies the program to be encrypted
The code is as follows:
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).
In addition, shc also provides a way to set a valid execution period. You can first use shc to convert shell programs to binary and add expiration time, such as:
The code is as follows:
# shc-e 18Compact 10Compact 2006-m "It's too late to run this script"-f script.s
At this point, I believe you have a deeper understanding of "how to encrypt shell scripts under CentOS". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!