简体   繁体   English

Upstart脚本启动eCryptfs加密

[英]Upstart script to start eCryptfs encryption

I'm using eCryptfs to mount and encrypt a particular directory via: 我正在使用eCryptfs通过以下方式挂载和加密特定目录:

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

I've seen examples that use fstab to automatically mount using ecryptfs at boot time. 我已经看到了一些示例,这些示例在启动时使用fstab自动使用ecryptfs进行挂载。

I'm wondering if it's possible / wise to do this as an upstart script, so that it can be executed as necessary and for testing purposes? 我想知道是否有可能/明智地将其作为暴发户脚本,以便可以根据需要执行它并出于测试目的?

Ideally it would run before other Upstart scripts that depend on the directory being encrypted. 理想情况下,它将在依赖于加密目录的其他Upstart脚本之前运行。

Please check the following script found at ruxkor's gist ( original , superuser ): 请检查在ruxkor的要旨中找到的以下脚本( originalsuperuser ):

#!/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

You may extend this script to use parameterized passphrase, eg: 您可以扩展此脚本以使用参数化密码短语,例如:

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

or: 要么:

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

Modify the script as required. 根据需要修改脚本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM