0

我正在使用 eCryptfs 通过以下方式挂载和加密特定目录:

mount -t ecryptfs /secure /secure -o ecryptfs_unlink_sigs,ecryptfs_key_bytes=16,ecryptfs_cipher=aes

我见过使用 fstab 在引导时使用 ecryptfs 自动挂载的示例。

我想知道是否有可能/明智地将其作为一个新贵脚本来执行,以便可以根据需要执行它并用于测试目的?

理想情况下,它将在其他依赖于被加密目录的 Upstart 脚本之前运行。

4

1 回答 1

0

请检查在ruxkor 的 gist ( original , superuser ) 中找到的以下脚本:

#!/bin/bash

# ecryptFS mount script
# taken and slightly modified version
# original at https://superuser.com/questions/227713/ecryptfs-how-to-mount-a-backup-of-an-encrypted-home-dir

# ROOT should be the parent of the .ecryptfs and .Private folders
if [ ! -d "$1" -o "$2" == "" ]; then
    echo "usage: $0 /home/.ecryptfs/USER /mnt/USER"
    exit 1
fi

ROOT=$1
TARGET=$2

sudo mkdir -p $TARGET
cd $ROOT

echo Type your password:
PASS=$(ecryptfs-unwrap-passphrase .ecryptfs/wrapped-passphrase | sed s/Passphrase:\ //)
SIG1=$(head -n1 .ecryptfs/Private.sig)
SIG2=$(tail -n1 .ecryptfs/Private.sig)

echo Passphrase:
echo $PASS
echo Signatures:
echo $SIG1
echo $SIG2

echo Should be empty:
sudo keyctl clear @u
sudo keyctl list @u

echo Do not type anything:
echo $PASS | sudo ecryptfs-add-passphrase --fnek

echo Sould have signatures:
sudo keyctl list @u

echo Mounting $ROOT on $TARGET...
sudo mount -t ecryptfs -o key=passphrase,ecryptfs_cipher=aes,ecryptfs_key_bytes=16,ecryptfs_passthrough=no,ecryptfs_enable_filename_crypto=yes,ecryptfs_sig=$SIG1,ecryptfs_fnek_sig=$SIG2,passwd=$(echo $PASS) .Private $TARGET

ls $TARGET

您可以扩展此脚本以使用参数化密码,例如:

ecryptfs-unwrap-passphrase .ecryptfs/wrapped-passphrase PASS

或者:

printf "%s" "wrapping passphrase" | ecryptfs-unwrap-passphrase [file] -

根据需要修改脚本。

于 2014-10-08T20:33:44.770 回答