Search This Blog

Thursday, 8 December 2016

Encrypt shell script using shc in linux

For shell script encryption you need to install shc package

1. install shc

2. extract shc-3.8.7.tgz and compile

tar xvfz shc-3.8.7.tgz

cd shc-3.8.7/


How To Encrypt Shell Script ??

Create a sample bash shell script that you like to encrypt using shc for testing purpose.
For testing purpose, let us create the following shell script which generates random numbers. You have to specify how many random numbers you like to generate.

$ nano

echo -n "How many random numbers do you want to generate? "
read max

for (( start = 1; start <= $max; start++ ))
  echo -e $RANDOM

$ ./
How many random numbers do you want to generate? 3
shc -r -T -f
This will create the following two files:
$ ls -l*
-rwxrw-r--. 1 purval purval 149 Mar 27 01:09
-rwx-wx--x. 1 purval purval 11752 Mar 27 01:12
-rw-rw-r--. 1 purval purval 10174 Mar 27 01:12

  • is the original unencrypted shell script
  • is the encrypted shell script in binary format
  • is the C source code of the file. This C source code is compiled to create the above encrypted file. The whole logic behind the shc is to convert the shell script to C program (and of course compile that to generate the executable)
$ file Bourne-Again shell script text executable

$ file ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, stripped

$ file ASCII C program text

Now, let us execute the encrypted shell script to make sure it works as expected.
$ ./
How many random numbers do you want to generate? 3

Cups printing issue

CUPS: Adding printer fails with “Unable to get list of printer drivers: Success” When installing a new printer using the CUPS web inter...