Automounting

使用 autofs、encfs 和密鑰環訪問自動掛載

  • September 2, 2016

我已經為自己建立了一個不錯的設置:

我已經加密了可使用 autofs 掛載的 encfs 文件夾,即當我輸入文件夾時,它們將被自動解密。我已將 encfs 密碼添加到我的密鑰環中,並編寫了一個提取密碼的自定義腳本(/usr/local/sbin/load-encfs見下文)。

唯一的缺點是我必須輸入我的登錄密碼才能在第一次訪問任何自動安裝的文件夾時解鎖密鑰環。每次訪問另一個文件夾(或超時後相同)都不會提示我輸入密碼。

**問題:**有沒有可能第一個密碼提示也可以以某種方式自動化?


/etc/autofs/auto.master:

我剛剛添加了這一行:

/-  /etc/autofs/auto.encfs

/etc/autofs/auto.encfs:

/home/user/Privat -fstype=fuse  :load-encfs\#user\:/home/user/encfs-keys/private.xml\:/home/user/Dropbox/.private
/home/user/BTU -fstype=fuse :load-encfs\#user\:/home/user/encfs-keys/btu.xml\:/home/user/Dropbox/.btu
/home/user/TUD -fstype=fuse :load-encfs\#user\:/home/user/encfs-keys/tud.xml\:/home/user/Dropbox/.tud

/usr/local/sbin/load-encfs(魚腳本):

#!/usr/bin/fish

function usage
   echo "need at least two arguments"
   echo "  1. <user name>:[<config>]:<crypt folder>"
   echo "  2. <mount folder>"
   exit 1
end

if test (count $argv) -lt 2
   usage
end

set split (string split ':' $argv[1])
if test $status -ne 0
   usage
else if test (count $split) -eq 2
   set USER_NAME $split[1]
   set CONFIG_PATH ""
   set CRYPT_PATH (realpath $split[2])
else
   set USER_NAME $split[1]
   set CONFIG_PATH (realpath $split[2])
   set CRYPT_PATH (realpath $split[3])
end

set MOUNT_PATH (realpath $argv[2])

set PID (ps aux | sed -e '/sed/d;/$USER_NAME.*xinit/!d;s/^.*xserverrc \(:[0-9\.]*\).*/aaa/' | awk '{ print $2 }')
if test -n "$PID"
   set DISPLAY (cat /proc/$PID/environ | tr '\0' '\n' | grep '^DISPLAY=' | sed -r 's/.*=(.*)/\1/')
end
if test -z "$DISPLAY"
   set DISPLAY ":0.0"
end

set PASS (env DISPLAY=$DISPLAY sudo -H -u $USER_NAME secret-tool lookup server $CRYPT_PATH)

if test -n $CONFIG_PATH
   set COMMAND "env ENCFS6_CONFIG=$CONFIG_PATH"
end

set COMMAND $COMMAND "encfs --public --extpass='echo \'$PASS\'' $CRYPT_PATH $MOUNT_PATH"
eval $COMMAND

我添加了各種參數以靈活地儲存 encfs 的配置文件。

在更新後遇到dbus問題後,我終於找到了解決方案。新腳本:

#!/usr/bin/fish

function usage
   echo "need at least two arguments"
   echo "  1. <user name>:[<config>]:<crypt folder>"
   echo "  2. <mount folder>"
   exit 1
end

if test (count $argv) -lt 2
   usage
end

set split (string split ':' $argv[1])
if test $status -ne 0
   usage
else if test (count $split) -eq 2
   set USER_NAME $split[1]
   set CONFIG_PATH ""
   set CRYPT_PATH (realpath $split[2])
else
   set USER_NAME $split[1]
   set CONFIG_PATH (realpath $split[2])
   set CRYPT_PATH (realpath $split[3])
end

set MOUNT_PATH (realpath $argv[2])

set PASS (sudo -H -u $USER_NAME bash -c "env DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/`id -u $USER_NAME`/bus secret-tool lookup server $CRYPT_PATH")

if test -n $CONFIG_PATH
   set COMMAND "env ENCFS6_CONFIG=$CONFIG_PATH"
end

set COMMAND $COMMAND "encfs --public --extpass='echo \'$PASS\'' $CRYPT_PATH $MOUNT_PATH"
eval $COMMAND

引用自:https://unix.stackexchange.com/questions/289522