shell中tar加密打包

tar 打包是一个很常见的操作,但是当打了一个包却又不想让别人看到里面的小秘密的时候就可以使用加密的方法进行打包。

以下是一个脚本实现的加密打包和解密的shell脚本:

cat tar_password.sh

 1 #!/bin/bash
 2 read -p "你的密码是: " PAS_WD
 3 case $1 in
 4 C)
 5     tar -zcvf - ${2}|openssl des3 -salt -k ${PAS_WD} | dd of=${2}.des3
 6     #tar -zcvf - {DIR}|openssl des3 -salt -k password | dd of={DIR}.des3
 7      #会生成一个 {DIR}.des3的文件
 8     echo "password: ${PAS_WD}" >> $2_password
 9 ;;
10 X)
11     dd if=${2} |openssl des3 -d -k ${PAS_WD}|tar zxf -
12     #dd if=config.des3 |openssl des3 -d -k password|tar zxf -
13 ;;
14 *)
15 echo "help"
16 echo "sh tar_password.sh C [dir]"
17 echo "sh tar_password.sh X [dir]"
18 ;;
19 esac

 

假设想要打包的文件(文件夹)名字为test
打包:
sh  tar_password.sh C test

(会提示你设置密码!!!)

将会生成 test.des3 (压缩包)和 test_password(密码文件)

 

解包:

sh  tar_password.sh X test.des3

(会提示你设置密码!!!)

将会解压出 test (文件/目录)

posted @ 2019-02-19 15:11  壹个龍宝宝宝  阅读(2618)  评论(0编辑  收藏  举报