2016-10-26 130 views
-1

我正在嘗試設置允許用戶掛載CIFS共享的systemd服務。這是我的了:Systemd服務請求密碼

mount_cifs @。服務

[Unit] 
Description=Mount CIFS share by %i 
After=network-online.target 
Wants=network-online.target 

[Service] 
Type=oneshot 
RemainAfterExit=yes 
ExecStartPre=/bin/mkdir -p /mnt/dir 
ExecStart=/bin/mount -t cifs //remote/path /mnt/dir -o username=%i 
ExecStop=/bin/umount /mnt/dir 
ExecStopPost=/bin/rmdir /mnt/dir 

然而,當我運行systemctl start [email protected],我得到以下信息:

Password for [email protected]//remote/path: 
Broadcast message from [email protected] (Wed 2016-10-26 21:24:56 CEST): 

Password entry required for 'Password for [email protected]//remote/path:' (PID 5677). 
Please enter password with the systemd-tty-ask-password-agent tool! 

正是我怎麼用這個工具?

+0

查詢systemd-tty-ask-password-agent工具的文檔後,您對如何使用它有什麼疑問? –

+0

我已閱讀[文檔](https://www.freedesktop.org/software/systemd/man/systemd-tty-ask-password-agent.html),但我不明白我必須使用哪個命令提示用戶輸入密碼。鍵入'systemd-tty-ask-password-agent'(+選項)沒有太多... – gncs

+0

您是否閱讀過[有關systemd和密碼提示的網絡相關問答](http://stackexchange.com/search ?q = systemd +密碼),特別是這個[systemd在啓動時提示輸入密碼](http://unix.stackexchange.com/questions/77769/prompt-for-password-during-boot-with-systemd-service ) –

回答

0

經過一番閱讀,我發現pwd=$(systemd-ask-password "Password:")是至少有一種方法。現在systemd不再抱怨。