使用SHC命令工具加密Shell脚本

问题:如何在Linux环境中加密shell 脚本

应用场景:

  1.当shell脚本中包含密码,不希望其他人查看到shell脚本中的密码等信息,可以安装使用SHC工具进行加密。

安装SHC

系统环境:Centos7

yum -y install shc

创建一个shell脚本

c

cat test.sh
#!/bin/sh
echo "Welcome to linux world"
chmod +x test.sh

使用SHC加密改脚本文件

[root@node1 ~]# shc -v -f test.sh
shc shll=sh
shc [-i]=-c
shc [-x]=exec '%s' "$@"
shc [-l]=
shc opts=
shc: cc   test.sh.x.c -o test.sh.x
shc: strip test.sh.x
shc: chmod ug=rwx,o=rx test.sh.x
[root@node1 ~]# ll test.sh*
-rwxr-xr-x. 1 root root    40 Mar 23 20:08 test.sh
-rwxrwxr-x. 1 root root 11200 Mar 24 09:55 test.sh.x
-rw-r--r--. 1 root root 17662 Mar 24 09:55 test.sh.x.c
[root@node1 ~]#

在这里插入图片描述

test.sh 是原始的未加密
shell脚本 test.sh.x 是二进制格式的加密shell脚本
test.sh.x.c 是test.sh 文件的C源代码。

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

[root@node1 ~]# file test.sh
test.sh: POSIX shell script, ASCII text executable
[root@node1 ~]# file test.sh.x
test.sh.x: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=4e4076c4425cd5c26553f1fd8d2e50f86a223b86, stripped
[root@node1 ~]# file test.sh.x.c
test.sh.x.c: C source, ASCII text
[root@node1 ~]#

在这里插入图片描述

执行加密后的shell脚本

ps:尝试执行加密后的shell脚本,确保他能正常运行

[root@node1 ~]# ./test.sh.x
Welcome to linux world
[root@node1 ~]#

在这里插入图片描述

指定Shell脚本的过期时间

[root@node1 ~]# rm -rf test.sh.x*
[root@node1 ~]# shc -e 24/03/2021 -v -f test.sh
shc shll=sh
shc [-i]=-c
shc [-x]=exec '%s' "$@"
shc [-l]=
shc opts=
shc: cc   test.sh.x.c -o test.sh.x
shc: strip test.sh.x
shc: chmod ug=rwx,o=rx test.sh.x
[root@node1 ~]# ./test.sh.x
./test.sh.x: has expired!
Please contact your provider jahidulhamid@yahoo.com
[root@node1 ~]#

在示例中,如果有人执行了test.sh.x脚本文件后,会提示已过期
在这里插入图片描述
如果想要指定自定义到期消息,需要添加-m 参数选项

[root@node1 ~]# shc -e 24/03/2021 -m "The script has expired, please contact Aihuidi" -v -f test.sh
shc shll=sh
shc [-i]=-c
shc [-x]=exec '%s' "$@"
shc [-l]=
shc opts=
shc: cc   test.sh.x.c -o test.sh.x
shc: strip test.sh.x
shc: chmod ug=rwx,o=rx test.sh.x
[root@node1 ~]# ./test.sh.x
./test.sh.x: has expired!
The script has expired, please contact Aihuidi
[root@node1 ~]#

在这里插入图片描述

  • 1
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值