Linux: Compiling a Bash Script into Binary / Linux / Linux: Compiling a Bash Script into Binary

Bash shell scripts in Linux are used in plaintext. Obfuscation allows you to hide a Bash script’s source code by compiling it into a binary. On Linux, you can use the shc tool to compile bash scripts. This tool can convert bash script code into C language and compile it. The output will be a binary file that can be run on almost any other Linux machine.

In this example, we’ll show how to compile a simple Bash script

echo "Hello, $1?"

Install the shc package (this generic shell script compiler requires gcc):

$ sudo apt install shc gcc

Install Shc (shell script compiler)

To compile your bash script into a binary file, run the command:

$ shc -rf
The -r option allows you to compile a portable binary that can be used on other computers.

The tool will create two files in the current directory:

  • – binary file
  • – source code C file

convert shell script into a binary executable

The binary contents are encrypted and the user won’t be able to view your shell script source code.

binary script file

You can now run the binary:

$ ./ SuperAdm

Compiling a bash/shell script to binary

With shc, you can specify the program’s validity date. Once it expires, your binary cannot run:

$ shc -e 31/03/2024 -m "Script code has expired!" -rf

./ has expired!

shc script has expired

For your convenience, you can rename the resulting binary file:

$ mv testapp

Allow the file to run:

$ chmod a+x testapp
To decrypt binary files that were created with an shc version < 4.0.3, you can use the tool
Leave a Reply

Your email address will not be published. Required fields are marked *