这篇文章主要介绍“SHC怎么对Shell脚本进行加密”的相关知识,小编通过实际案例向大家展示操作过程,操作方法简单快捷,实用性强,希望这篇“SHC怎么对Shell脚本进行加密”文章能帮助大家解决问题。

环境

Centos8

安装shc

[root@localhost~]#yum-yinstallshc

创建一个shell脚本

下面创建一个脚本文件:

[root@localhost~]#vimwelcome.sh#!/bin/shecho"Welcometolinuxworld"使用shc加密该脚本文件

如下所示,使用shc加密welcome.sh脚本。

[root@localhostscripts]#shc-v-fwelcome.shshcshll=shshc[-i]=-cshc[-x]=exec'%s'"$@"shc[-l]=shcopts=shc:ccwelcome.sh.x.c-owelcome.sh.xshc:stripwelcome.sh.xshc:chmodug=rwx,o=rxwelcome.sh.x

welcome.sh 是原始的未加密shell脚本
welcome.sh.x 是二进制格式的加密shell脚本
welcome.sh.x.c 是welcome.sh文件的C源代码。编译该C源代码以创建上面的加密的welcome.sh.x文件。

可以使用file命令查看文件的类型:

[root@localhostscripts]#filewelcome.shwelcome.sh:POSIXshellscript,ASCIItextexecutable[root@localhostscripts]#filewelcome.sh.xwelcome.sh.x:ELF64-bitLSBexecutable,x86-64,version1(SYSV),dynamicallylinked,interpreter/lib64/ld-linux-x86-64.so.2,forGNU/Linux3.2.0,BuildID[sha1]=35e0e2569eca90774e379d6fef51ad6fedf346f5,stripped[root@localhostscripts]#filewelcome.sh.x.cwelcome.sh.x.c:Csource,ASCIItext[root@localhostscripts]#

执行加密后的shell脚本

现在,让我们执行加密的Shell脚本,确保能够运行:

[root@localhostscripts]#./welcome.sh.xWelcometolinuxworld

指定Shell脚本的过期时间

使用shc,您还可以指定到期日期。即在这个到期日期之后,当有人尝试执行Shell脚本时,将收到错误消息。使用shc -e选项创建一个新的加密Shell脚本,指定到期日期。到期日期以dd/mm/yyyy 格式指定。

#删除之前创建的.x,.x.c文件[root@localhostscripts]#rm-rfwelcome.sh.x*#创建带有过期时间的加密脚本[root@localhostscripts]#shc-e01/02/2021-v-fwelcome.shshcshll=shshc[-i]=-cshc[-x]=exec'%s'"$@"shc[-l]=shcopts=shc:ccwelcome.sh.x.c-owelcome.sh.xshc:stripwelcome.sh.xshc:chmodug=rwx,o=rxwelcome.sh.x

在此示例中,如果有人尝试执行welcome.sh.x脚本文件,会提示已过期。

[root@localhostscripts]#./welcome.sh.x./welcome.sh.x:hasexpired!Pleasecontactyourproviderjahidulhamid@yahoo.com

如果要指定自定义到期消息,需要加入-m选项。

[root@localhostscripts]#shc-e01/02/2021-m"Pleasecontactadmin@example.com!"-v-fwelcome.shshcshll=shshc[-i]=-cshc[-x]=exec'%s'"$@"shc[-l]=shcopts=shc:ccwelcome.sh.x.c-owelcome.sh.xshc:stripwelcome.sh.xshc:chmodug=rwx,o=rxwelcome.sh.x

关于“SHC怎么对Shell脚本进行加密”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识,可以关注亿速云行业资讯频道,小编每天都会为大家更新不同的知识点。