03月04, 2020
收藏本站

shell脚本加密 - shc

经常写shell脚本的,可能会想对自己的脚本进行“保护”,如有些密码不愿被看到,脚本不愿被随意修改,这时就需要shc进行加密了。

建议将shc安装在Centos6中,经测试在7加密的脚本,在低版本的6可能会执行错误

一、安装

wget http://www.datsi.fi.upm.es/~frosal/sources/shc-3.8.9b.tgz
tar zxvf shc-3.8.9b.tgz 
cd shc-3.8.9b
mkdir -p /usr/local/man/man1/
make install

二、运行

shc -T -r -f test.sh

三、详解

[root@localhost ~]# shc -h
shc Version 3.8.9b, Generic Script Compiler
shc Copyright (c) 1994-2015 Francisco Rosales <frosal@fi.upm.es>
shc Usage: shc [-e date] [-m addr] [-i iopt] [-x cmnd] [-l lopt] [-rvDTCAh] -f script

    -e %s  Expiration date in dd/mm/yyyy format [none]  过期时间
    -m %s  Message to display upon expiration ["Please contact your provider"] 过期提醒文字
    -f %s  File name of the script to compile 要加密的文件名
    -i %s  Inline option for the shell interpreter i.e: -e  shell解释器的内联选项
    -x %s  eXec command, as a printf format i.e: exec('%s',@ARGV);
    -l %s  Last shell option i.e: --
    -r     Relax security. Make a redistributable binary  放松安全。生成可再发行的二进制文件
    -v     Verbose compilation
    -D     Switch ON debug exec calls [OFF]
    -T     Allow binary to be traceable [no]  允许二进制文件可跟踪
    -C     Display license and exit
    -A     Display abstract and exit
    -h     Display help and exit

    Environment variables used:
    Name    Default  Usage
    CC      cc       C compiler command
    CFLAGS  <none>   C compiler flags

    Please consult the shc(1) man page.

设置脚本过期时间:

shc -r -T -e "4/3/2020" -m "this file is expiration date." -f test.sh

四、常见问题

1、报错:[2]+ Stopped

[root@localhost ~]# ./test.sh.x
[2]+  Stopped                 ./test.sh.x

需要加个 -T参数: shc -v -r -T -f test.sh


Comments