1

我用来rsync将客户端上的数据与服务器上的解密 ecryptfs-container 同步。

我想要实现的是以下自动过程:

  1. 如果在服务器上keyctl show已经有我想要的密钥签名,请转到 (3.)
  2. ecryptfs-add-passphrase --fnek将我的密钥添加到服务器上的密钥环
  3. mount -i /mnt/path/to/decrypted确保解密的文件夹安装在服务器上
  4. rsync从客户端到服务器
  5. 可选:卸载文件夹并删除密钥签名(此处不重要)

目前,对于步骤 1、2、3,我用于ssh -tq ...执行命令并评估结果。

我的问题如下:似乎 ecryptfs 需要服务器上的持久用户会话。否则,由于用户注销(ssh -tq ...命令完成后结束),密钥被添加并立即删除。

我刚刚认识到这ssh -tq 'ecryptfs-add-passphrase --fnek; mount -i /mnt/path/to/decrypted'显然按预期工作。之后再次删除密钥,但安装成功。这意味着我必须在服务器上实现“动态提示”(步骤 1)。这已经是最好的解决方案还是我也可以在客户端上实现这一点?

4

1 回答 1

1

我今天几次偶然发现您的帖子,同时试图准确地了解您所描述的内容,但没有找到任何帮助。我终于设法自己找到了解决方案。

此解决方案是利用--rsync-pathrsync 的选项。这是手册页的摘录:

    --rsync-path=PROGRAM
          Use this to specify what program is to  be  run  on  the  remote
          machine  to start-up rsync.  Often used when rsync is not in the
          default      remote-shell’s      path       (e.g.       --rsync-
          path=/usr/local/bin/rsync).   Note  that PROGRAM is run with the
          help of a shell, so it can be any program,  script,  or  command
          sequence  you’d  care to run, so long as it does not corrupt the
          standard-in & standard-out that rsync is using to communicate.

          One tricky example is to set a different  default  directory  on
          the  remote  machine  for  use  with the --relative option.  For
          instance:

              rsync -avR --rsync-path="cd /a/b && rsync" hst:c/d /e/

手册最后一段给出的例子给了我使用这个参数挂载ecryptfs目录的想法。

这是代码:

rsync --rsync-path="(printf \"%s\" \"$passphrase\" | ecryptfs-add-passphrase --fnek && ecryptfs-mount-private) &> /dev/null && rsync" -aKLv local_to_sync remotehost.com:~/Private/
于 2016-09-11T21:24:55.660 回答