Encrypting your shell script in linux using shc utility





Unix or Linux admin often used various shell script to perform automation in project or meaning to reduction in efforts. this is a very good practice for projects and in it helps admin a lot. But some time an admin dont want everyone to see what codes he used to write. A shell script normally a text file of a group of command sequence to perform specific task and hence it is very obvious that any one can read this test file and can find what is written in script and can understand the logic.

So here is an option if an admin dont want to show is codes to some one but want to give ability that some one can execute his script for performing the same task. shc is an option. shc encrypts the shell script and it turns into binary mode which cannot be read.

Lets understand how we can use it.

I have one script for getting VM ip's from my KVM host machine .

# vim getvmip
content of script is as bellow -

#!/bin/bash
VMMAC=$(virsh dumpxml $1 | grep "mac address" | awk -F\' '{ print $2}')
VMIP=$(arp -an | grep $VMMAC | awk '{print $2}' | cut -d "(" -f2 | cut -d ")" -f1 )
echo "Domain $1 ip is : $VMIP"

When i execute this script with any of vm ( KVM domain ) name it returns the guest VM IP.

# ./getvmip vmv1
Domain vmv1 ip is : 192.168.122.6

Now in order to encrypt my this script, i will install shc first in my centos 7 machine
i need gcc and make utility to be already there in order to compile this shc source.
Download the source

# wget https://github.com/neurobin/shc/archive/release.tar.gz
# tar xvf  release.tar.gz
# cd  shc-release
# ./configure
# make
# make install

Now i can use shc command to encrypt my code 
I will run bellow to encrypt this

# shc -v -r  -f  getvmip

And above will generate two file

getvmip.x and getvmip.x.c   where  getvmip.x is my executable binary file which i can reditribute to anyone and the same script will run there also ..

Cheers !!

Comments

Popular posts from this blog

Running web ssh client on port 443 /80 with nginx as reverse proxy

Running cockpit behind nginx reverse proxy with nginx ssl and cockpit non ssl

Setup VOD streaming server with nginx using RTMP on Ubuntu 18.04