日日操夜夜添-日日操影院-日日草夜夜操-日日干干-精品一区二区三区波多野结衣-精品一区二区三区高清免费不卡

公告:魔扣目錄網為廣大站長提供免費收錄網站服務,提交前請做好本站友鏈:【 網站目錄:http://www.ylptlb.cn 】, 免友鏈快審服務(50元/站),

點擊這里在線咨詢客服
新站提交
  • 網站:51998
  • 待審:31
  • 小程序:12
  • 文章:1030137
  • 會員:747

如何在linux環境中加密shell腳本?shell腳本包含密碼,不希望其他具有執行權限的人查看shell腳本并獲取密碼。可以安裝使用shc工具,普通用戶無法讀取shc創建的加密Shell腳本。SHC是指:Shell腳本編譯器(Shell Script Compiler)。

環境

centos8

安裝shc

[root@localhost ~]# yum -y install shc
如何加密Shell腳本

 

創建一個shell腳本

下面創建一個腳本文件:

[root@localhost ~]# vim welcome.sh

#!/bin/sh
echo "Welcome to linux world"

使用shc加密該腳本文件

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

[root@localhost scripts]# shc -v -f welcome.sh 
shc 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
如何加密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.sh
welcome.sh: POSIX shell script, ASCII text executable
[root@localhost scripts]# file welcome.sh.x
welcome.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.c
welcome.sh.x.c: C source, ASCII text
[root@localhost scripts]# 
如何加密Shell腳本

 

執行加密后的shell腳本

現在,讓我們執行加密的Shell腳本,確保能夠運行:

[root@localhost scripts]# ./welcome.sh.x 
Welcome to linux world
如何加密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.sh 
shc 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
如何加密Shell腳本

 


在此示例中,如果有人嘗試執行welcome.sh.x腳本文件,會提示已過期。

[root@localhost scripts]# ./welcome.sh.x 
./welcome.sh.x: has expired!
Please contact your provider [email protected]
如何加密Shell腳本

 


如果要指定自定義到期消息,需要加入-m選項。

[root@localhost scripts]# shc -e 01/02/2021 -m "Please contact [email protected]!" -v -f welcome.sh 
shc 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
如何加密Shell腳本

 

總結

本文介紹了如何使用shc加密shell腳本。

分享到:
標簽:腳本 Shell
用戶無頭像

網友整理

注冊時間:

網站:5 個   小程序:0 個  文章:12 篇

  • 51998

    網站

  • 12

    小程序

  • 1030137

    文章

  • 747

    會員

趕快注冊賬號,推廣您的網站吧!
最新入駐小程序

數獨大挑戰2018-06-03

數獨一種數學游戲,玩家需要根據9

答題星2018-06-03

您可以通過答題星輕松地創建試卷

全階人生考試2018-06-03

各種考試題,題庫,初中,高中,大學四六

運動步數有氧達人2018-06-03

記錄運動步數,積累氧氣值。還可偷

每日養生app2018-06-03

每日養生,天天健康

體育訓練成績評定2018-06-03

通用課目體育訓練成績評定