- 论坛徽章:
- 0
|
在liunx 下使用加密文件系统,相对简单的多。。
本例使用内核自备的 Cryptoloop 来建立 aes 加密的文件系统映像文件。
首先要在内核中启用Cryptoloop:
Device Drivers/Block devices 里的 Loopback device support 为 Y,Cryptoloop Support 为 M 或 Y(本例脚本对应的是M)
其次,要在 Cryptographic API 里将 AES cipher algorithms(AES cipher algorithms (i586))为 M 或 Y
然后参考下面的脚本(保存为任意名.sh,然后chmod +x 给予运行权限,运行它):
#!/bin/bash
# by ArLi, program@163.com 200804
if [ "$LOGNAME" != "root" ]
then
echo "You need to be root to run this script" >&2
exit 1;
fi
if [ "$#" -lt 1 ]
then
echo "syntax:";
echo "\"$0 c imagefilename bytes[K/M/G]\" to create image";
echo "\"$0 m imagefilename\" to mount";
echo "\"$0 u\" to umount";
elif [ "$1" = "c" ]
then
if [ "$#" -lt 3 ]
then
echo "args error!" >&2
exit 1;
fi;
echo "delete $2 if exist..";
rm -f $2;
echo "create image..";
touch $2;
echo "shred new image..";
shred -n1 -s$3 $2;
if (($(lsmod |grep -c "cryptoloop") 1))
then
echo "cryptoloop load..";
modprobe cryptoloop;
fi;
declare loopX=`losetup -f`
echo "setup encrypting @ $loopX, input password pls..";
losetup -e aes $loopX $2;
echo "format image..";
mkfs.ext3 $loopX
echo "$2 created";
losetup -d $loopX
elif [ "$1" = "m" ]
then
if [ "$#" -lt 2 ]
then
echo "imagefilename need!" >&2
exit 1;
fi;
if (($(lsmod |grep -c "cryptoloop") 1))
then
echo "cryptoloop load..";
modprobe cryptoloop;
fi;
mount -t ext3 $2 /mnt/encrypt -oencryption=aes;
elif [ "$1" = "u" ]
then
umount /mnt/encrypt;
if (($(lsmod |grep -c "cryptoloop") > 0))
then
echo "cryptoloop unload..";
modprobe -r cryptoloop;
fi;
else
echo "wrong command." >&2
fi
对于aes 未自动载入的可自行在脚本里加上 modprobe aes_generic(aes-i586),可用 cat /proc/crypto 确定 aes 是否已开始工作。
脚本中的 modprobe 也可换成 insmod 和 rmmod。
脚本中的挂载点是 /mnt/encrypt 可自行更改。
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/27936/showart_516110.html |
|