In many cases, we need to protect our shell script source code from being easily viewed by others. At this time, useshc
Tools compile shell scripts into binary files is an efficient way. This article will introduce in detail how to install online and offline conditionsshc
and use it to compile your scripts.
What is SHC?
shc
Is a Shell script encryption program written in C language that can compile your scripts into binary executables, thus hiding the source code.
Install SHC
Install online
If your machine is able to connect to the internet, the following is installed on different operating systemsshc
Steps:
- Ubuntu:
sudo apt-get install shc
- macOS:
brew install shc
- CentOS:
yum install shc
Offline installation
If your machine cannot connect to the Internet, then you can download it in an environment with a network.shc
Source code package and install offline.
- Download the shc source code package in an environment with network
Download link:/neurobin/shc/archive/refs/tags/4.0.
- Copy the file to the target machine
It can be transmitted through a USB storage device or a local area network.
Install shc on the target machine
tar -xvzf shc-4.0. cd shc-4.0.3 mkdir -p /usr/local/man/man1 #This step is necessary, otherwise an error will be reported during the installation process. shc will put the installation command into /usr/local/bin/ directory; store the help document in /usr/local/man/man1/ directory. If there is no such directory in the system, an error will be reported during installation. You can create this directory and then execute the installation.make sudo make install #This step needs to be answeredyesory,Can't go back directly,Otherwise, an error will be reported
- Verify installation
After the installation is completed, you can check it by following the commandshc
Is it installed successfully:
shc -v
If you can see the version information, it meansshc
Installed successfully.
Compile scripts using SHC
Suppose you have a name calledshell script and want to compile it into binary files to hide the source code. It can be done in just two steps:
- use
shc
Compile
Enter the following command on the command line:
shc -f #“-f”Options specify the program to be encrypted
This operation generates two new files:and
。
is an executable binary file, and
It is the C source file that generates binary files.
- Run the compiled script
You can run the compiled binary file directly:
./
Please note that althoughshc
It can be nice to hide your source code and prevent light reverse engineering, but if higher levels of protection are required, you may need to rewrite the script to a compiled language (such as C, Go, or Rust), or encapsulate and encrypt with a dedicated software encryption tool.
This is the article about how to use SHC to encapsulate and source code to hide Shell scripts. For more information about using SHC to encapsulate and source code to hide Shell scripts, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!