温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

SHC怎么对Shell脚本进行加密

发布时间:2022-02-17 15:33:19 来源:亿速云 阅读:218 作者:iii 栏目:开发技术

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

SHC怎么对Shell脚本进行加密

环境

Centos8

安装shc

[root@localhost ~]# yum -y install shc
SHC怎么对Shell脚本进行加密

创建一个shell脚本

下面创建一个脚本文件:

[root@localhost ~]# vim welcome.sh#!/bin/shecho "Welcome to linux world"

使用shc加密该脚本文件

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

[root@localhost scripts]# shc -v -f welcome.shshc shll=sh
shc [-i]=-c
shc [-x]=exec '%s' "$@"shc [-l]=
shc opts=
shc: cc   welcome.sh.x.c -o welcome.sh.x
shc: strip welcome.sh.x
shc: chmod ug=rwx,o=rx welcome.sh.x
SHC怎么对Shell脚本进行加密
  • welcome.sh 是原始的未加密shell脚本
  • welcome.sh.x 是二进制格式的加密shell脚本
  • welcome.sh.x.c 是welcome.sh文件的C源代码。编译该C源代码以创建上面的加密的welcome.sh.x文件。

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

[root@localhost scripts]# file welcome.shwelcome.sh: POSIX shell script, ASCII text executable
[root@localhost scripts]# file welcome.sh.xwelcome.sh.x: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=35e0e2569eca90774e379d6fef51ad6fedf346f5, stripped
[root@localhost scripts]# file welcome.sh.x.cwelcome.sh.x.c: C source, ASCII text
[root@localhost scripts]#
SHC怎么对Shell脚本进行加密

执行加密后的shell脚本

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

[root@localhost scripts]# ./welcome.sh.xWelcome to linux world
SHC怎么对Shell脚本进行加密

指定Shell脚本的过期时间

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

# 删除之前创建的.x , .x.c文件[root@localhost scripts]# rm -rf welcome.sh.x*# 创建带有过期时间的加密脚本[root@localhost scripts]# shc -e 01/02/2021 -v -f welcome.shshc shll=sh
shc [-i]=-c
shc [-x]=exec '%s' "$@"shc [-l]=
shc opts=
shc: cc   welcome.sh.x.c -o welcome.sh.x
shc: strip welcome.sh.x
shc: chmod ug=rwx,o=rx welcome.sh.x

SHC怎么对Shell脚本进行加密 

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

[root@localhost scripts]# ./welcome.sh.x./welcome.sh.x: has expired!
Please contact your provider jahidulhamid@yahoo.com

SHC怎么对Shell脚本进行加密

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

[root@localhost scripts]# shc -e 01/02/2021 -m "Please contact admin@example.com!" -v -f welcome.shshc shll=sh
shc [-i]=-c
shc [-x]=exec '%s' "$@"shc [-l]=
shc opts=
shc: cc   welcome.sh.x.c -o welcome.sh.x
shc: strip welcome.sh.x
shc: chmod ug=rwx,o=rx welcome.sh.x
SHC怎么对Shell脚本进行加密

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

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI