采用shc工具加密Shell脚本,以提升shell脚本文件的安全性。
介绍:当咱们写的shell脚本,存在有敏感信息如帐号密码,因而想增强脚本的安全性;还有不想让别人查看/修改您的shell核心代码等等状况。均可使用如下工具进行加密。
shc是一个脚本编译工具, 使用RC4加密算法, 它可以把shell程序转换成二进制可执行文件(支持静态连接和动态连接)。
shc官网:http://www.datsi.fi.upm.es/%7Efrosal/算法
安装shc
wget http://www.datsi.fi.upm.es/%7Efrosal/sources/shc-3.8.7.tgz
tar vxf shc-3.8.7.tgz
cd shc-3.8.7
make test
make strings
make installshell
若报错:
*** Installing shc and shc.1 on /usr/local
*** ?Do you want to continue? y
install -c -s shc /usr/local/bin/
install -c -m 644 shc.1 /usr/local/man/man1/
install: target `/usr/local/man/man1/' is not a directory: No such file or directory
make: *** [install] Error 1安全
请建立 mkdir -p /usr/local/man/man1/ ,而后运行make installide
经常使用参数:
-e date (指定过时日期)
-m message (指定过时提示的信息)
-f script_name(指定要编译的shell的路径及文件名)
-r Relax security. (能够相同操做系统的不一样系统中执行)
-v Verbose compilation(编译的详细状况)工具
使用方法:
shc -v -f abc.sh
-v 是现实加密过程
-f 后面跟须要加密的文件
运行后会生成两个文件:
abc.sh.x 和 abc.sh.x.c
abc.sh.x为二进制文件,赋予执行权限后,可直接执行。更更名字mv abc.sh.x a.sh
abc.sh.x.c 是c源文件。基本没用,能够删除测试
另shc还提供了一种设定有效执行期限的方法,过时时间,如:
# shc -e 28/01/2012 -m "过时了" -f abc.sh
选项“-e”指定过时时间,格式为“日/月/年”;选项“-m”指定过时后执行此shell程序的提示信息。
若是在过时后执行,则会有以下提示:
# ./abc.sh.x
./abc.sh.x: has expired!
过时了
使用以上方法要注意,需防止用户更改系统时间,能够经过在程序中加入自动更新系统时间的命令来解决此问题。加密
测试都已经过,请放心使用!操作系统