shell腳本加密形式

shell腳本在日常運維過程中顯得尤爲重要,通常我們在編寫shel腳本中會涉及到很多參數包括密碼等一些隱私信息,這個時需要將shell腳本加密,並且可執行結果。下面文章簡介兩種shell腳本加密方式:

shc加密方式

1、shc軟件安裝

cd /mnt //進入或者創建目錄,即選擇下載位置
wget http://www.datsi.fi.upm.es/~frosal/sources/shc-3.8.9.tgz //下載軟件包
tar zxvf shc-3.8.9.tgz -C /opt //解壓軟件包

解壓完成壓縮包後先不着急安裝,首先安裝環境依賴包:

yum install gcc gcc-c++ make -y
cd /opt/shc-3.8.9
make install //執行安裝

注:若安裝時報如下錯誤,則需創建工作目錄。
shell腳本加密形式

mkdir -p /usr/local/man/man1 //創建軟件默認工作目錄
make install //再次安裝即可

2、加密shell腳本

cd /opt
ls -l

-rw-r--r--. 1  root   root    38 6月  22 09:54 123.sh

shc -r -f 123.sh //對腳本進行shc加密
ls -l

-rwx--x--x. 1 root root 11184 6月 22 09:56 123.sh.x  //加密後的可執行的二進制文件
-rw-r--r--. 1 root root 9456 6月 22 09:56 123.sh.x.c  //生成123.sh.x的原文件(c語言)

./123.sh.x //執行加密後的shell腳本

this is test shell    //依舊可正常輸出

gzexe加密方式

gzexe加密shell腳本方式爲系統自帶,其功能比起shc而言相對較弱,只能滿足一般需求。

cd /opt
ls -l

-rw-r--r--. 1  root   root    38 6月  22 09:54 123.sh

gzexe 123.sh //加密文件
ls -l

-rw-r--r--. 1 root     root       864 6月  22 10:05 123.sh   //加密後文件
-rw-r--r--. 1 root     root        38 6月  22 09:54 123.sh~   //原文件備份文件

注:系統自帶的gzexe程序,它不但加密,同時壓縮文件,且加密後,原文件被備份成了123.sh~文件。

./123/sh

this is test shell    //可正常輸出
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章