If you wise to distribute your script but don’t want anyone to modification or inspection, follow the below procedure to protect the script by converting to binary executable format.
- Write a shell script. eg. my_script.sh
- If your system runs on RHEL5, Download & Install “shc” rpm from ftp://ftp.is.co.za/mirror/ftp.rpmforge.net/redhat/el5/en/i386/dag/RPMS/shc-3.8.6-1.el5.rf.i386.rpm For other version of OS, download & install the appropriate rpm version
- Execute the following commandshc –v –e 20/03/2011 –m “Command expired” –r –T –f <my_script.sh>
- –v Verbose compilation
- -r Relax security. Make a redistributable binary which executes on different systems running the same operating system.
- -T Allow binary to be traceable (using strace, ptrace, truss, etc.)
- -f <script name> File name of the script to compile
- -e <dd/mm/yyyy> Expiration date in dd/mm/yyyy format
- -m <message> message to display upon expiration
- Upon the compilation, you will get output similar to this
shc [-x]=exec ‘%s’ “$@”
shc: cc my_script.sh.x.c -o my_script.sh.x
shc: strip my_script.sh.x
shc: chmod go-r my_script.sh.x
- Verify the file type
my_script.sh.x: ELF 64-bit LSB executable, AMD x86-64, version 1 (SYSV), for GNU/Linux 2.6.9, dynamically linked (uses shared libs), for GNU/Linux 2.6.9, stripped
- Now you can execute the command & check the result
- Backup your original script and distribute the executable file.