To run a shell script in an encrypted mode


Scenario:  To encrypt a shell script for security reason and to call the encrypted shell script in another shell script.

Prerequisite for installing shc (encrypting a shell script):
Gcc library is required before installing shc application.

SHC installation in Centos:

Step1:  #yum install gcc

Step2: #yum install shc ( it will install shc.x86_64) based on the OS version.
Now steps to encrypt a shell script.

After the successful installation of SHC the following steps to be carried out.

Step3: create a shell script to display your login-id and the computer hostname.
Script1:
#!/bin/bash
Echo –n “I am logged on as”; whoami
Echo –n “ My computer name”; hostname
Save the file and close (:wq) - File name login.sh

Step4:  now run the command
#shc –f  login.sh
This will create two files a. login.sh.x b. login.sh.x.c

Step5:  Run the command to execute in another shell script
# shc –v  –r  -T –f  login.sh

Step 6: Create another script to call the encrypted script.
#!/bin/bash
PATH_TO_A=/root/login.sh.x
echo Calling sh login.sh.x
$PATH_TO_A

Step7:  Execute another script and check with the original one; both output must be similar.

One Response to To run a shell script in an encrypted mode

  1. tshrinivasan says:

    Good find.

    Thanks for sharing.

Leave a reply to tshrinivasan Cancel reply