How to encrypt bash shell script in Linux ?

Today in this post, we will see how to encrypt a shell script in Linux.

Lets have a look at this step by step.

1. Download shc source code from below links.
shc-master
Or, from GIT Repo: https://github.com/neurobin/shc

or,

We can download the RPM also from here:

https://pkgs.org/download/shc

 

2. Compile and install shc.

# ./configure
# make
# make install

 

3. Encrypt a file named script.sh.ri

[mike@ngelinux001 01_script]$ cd shc-master
[mike@ngelinux001 shc-master]$ ./shc -v -r -T -f script.sh.ri
shc shll=bash
shc [-i]=-c
shc [-x]=exec '%s' "$@"
shc [-l]=
shc opts=
shc: cc  script.sh.ri.x.c -o script.sh.ri.x
shc: strip script.sh.ri.x
shc: chmod go-r script.sh.ri.x
[mike@ngelinux001 shc-master]$

[mike@ngelinux001 script.sh.ri_v1]$ ls -ltr
total 176
-rwxr-xr-x 1 mike ngegroup1  7952 Oct 11 11:43 script.sh.ri
-rw-r--r-- 1 mike ngegroup1 50088 Nov 30 11:36 script.sh.ri.x.c
-rwx--x--x 1 mike ngegroup1 21120 Nov 30 11:36 script.sh.ri.x

 

4. Try to read the encrypted file.

[mike@ngelinux001 01_transfer_v1]$ more ./script.sh.ri.x
******** ./script.sh.ri.x: Not a text file ********
[mike@ngelinux001 01_transfer_v1]$

[mike@ngelinux001 01_transfer_v1]$ cat ./script.sh.ri.x 
ELF>▒   @@▒K@@@@@@▒@@@@▒▒   ` `4*h+ ( ( `( `▒@@DDP▒td▒▒@▒@ddQ▒t/lib64/ld-linux-x86-64.so.2GNUGNU▒▒Xt▒]▒5t0▒/Px▒▒0▒@▒ݣkʼn▒Ĺ▒@9▒S "▒y▒7L▒▒r▒Z>kE▒▒2▒!@J▒!@J▒@J▒HJ__gmon_start__libc.so.6sprintf__isoc99_sscanftimegetpidstrdupcallocstrlenmemset__errno_locationmem▒uiputen▒▒!`@J`HJ`▒!`▒!`▒!`▒!`▒!`"""`ntf"`ollstrerror__libc_start_main__environ__xstatGLIBC_2.7GLIBC_2.2.5ii
 "`
   ("`

So finally our bash script is encrypted and can’t be read by anyone.

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments