Encrypt shell scripts in linux

Introduction:

Let’s consider a scenario, You are working for company and as per company policy you cannot share your developed linux shell script(s) in human readable format so that source code is not exposed to the users in human readable format but script file is needed to shared across multiple users to execute code without code being exposed.

To find out the process of securing / encrypting your script, please continue reading ..

What is the process /approach?

Shell script compiler compiles your shell script and generate encrypted script (binary file) which can be used to share across multiple users with assurance of your source code being secured.

Lets gets started….

Lets create a simple shell script which uses echo command to display message as shown in below screenshot

To download shell compiler from internet and configure please follow below steps

wget -c http://www.datsi.fi.upm.es/~frosal/sources/shc-3.8.9b.tgz
tar -zvxf shc-3.8.9b.tgz
cd shc-3.8.9b

make

Now SHELL Script Compiler is ready for use, below is the syntax and options that are allowed.

Below command needs to be executed to encrypt our script.sh which can be executed on any other supported linux system

shc -v -r -T -f /tmp/demo/script.sh

Now 2 files are created in the same path as of script.sh, these files are with extensions .x.c (ASCII C program text) and .x (executable binary file)

/tmp/demo/script.sh.x can be renamed and shared across and it is not possible to view the contents of this binary file.

/tmp/demo/script.sh.x can be used to execute and share – As it is encrypted and secured.

For feedback, queries and clarifications then please submit using below comment section.

Leave a comment