如何在启动时使用systemd和init.d中的ssh-askpass

时间:2018-01-23 12:46:02

标签: bash mount systemd init.d ecryptfs

我正在使用ecryptfs加密目录/ opt /目录。我想使用systemd和init.d创建服务,提示用户输入加密密码并安装目录。我尝试在我的系统服务调用的脚本中使用ssh-askpass,但是当我的计算机启动时它没有提示输入密码,因此,目录未安装。

以下是我安装目录的脚本:

#!/bin/bash
SIG='/root/.ecryptfs/encryption.sig'
ECRYPTFS_WRAPPED_PASSWORD="/root/.ecryptfs/directory-encryption.wrapped"
    # test if authing and test if the mount point is not mounted
    if ! mountpoint -q "/opt/directory"; then
        PASSWORD=$(ssh-askpass)
        # insert the wrapped password and mount the directory, expose_authtok types the password into the
        # ecryptfs-insert-wrapped-passphrase-into-keyring command for us
        SIG=$(head -n 1 "$SIG")
        sudo -s -u "root" /bin/bash -c "printf "%s" "$PASSWORD" | ecryptfs-insert-wrapped-passphrase-into-keyring $ECRYPTFS_WRAPPED_PASSWORD && sudo mount -i -t ecryptfs /opt/directory /opt/directory -o ecryptfs_sig=$SIG,ecryptfs_fnek_sig=$SIG,ecryptfs_cipher=aes,ecryptfs_key_bytes=32,ecryptfs_unlink_sigs"
    fi

直接调用脚本工作正常,但在使用systemd启动时调用,它不会提示我输入密码。以下是我的systemd文件:

[Unit]
Description=Directory Encryption Service

[Service]
ExecStart=/root/.ecryptfs/directory-encryption-script
StandardOutput=null

[Install]
WantedBy=multi-user.target
Alias=directory a.encryption.service

0 个答案:

没有答案