Centos

CentOS 7 中 dovecot 和 postfix 的 ACL/MAC 權限

  • January 24, 2020

我正在使用本教程Web 伺服器進行設置Postfix``Dovecot``CentOS 7。但是,當我嘗試使用 發送測試電子郵件時sudo echo "TEST" | mail -s "testmail" newuser@localhost && sudo tail -f /var/log/maillog,我收到一條錯誤消息,表明 Dovecot 沒有創建用於儲存電子郵件的目錄的權限。如何設置權限DovecotPostfix能夠正常工作CentOS 7

我是新手linux。我知道adduser, chmod, chown, octal permissions, 和其他命令,但我不知道它們如何適用於這個特定的要求,我不想在沒有理解的情況下通過實驗來創造無效的東西。

這是錯誤消息中最相關的部分:

Error: user import: Initialization failed: Namespace '':  
mkdir(/home/import/Maildir) failed:  
Permission denied (euid=1001(import) egid=1001(import)  
missing +w perm: /home/import, UNIX perms appear ok (ACL/MAC wrong?))

這是完整的錯誤消息:

Dec 30 19:03:42 mydomain postfix/pickup[8093]: A22E78221C13: uid=1000 from=<anotherusername>
Dec 30 19:03:42 mydomain postfix/cleanup[8121]: A22E78221C13: message-id=<20141231000342.A22E78221C13@mydomain.com>
Dec 30 19:03:42 mydomain postfix/qmgr[8094]: A22E78221C13: from=<anotherusername@mydomain.com>, size=463, nrcpt=1 (queue active)
Dec 30 19:03:42 mydomain dovecot: lda(newusername): Error: user newusername: Initialization failed: Namespace '': mkdir(/home/newusername/Maildir) failed: Permission denied (euid=1001(newusername) egid=1001(newusername) missing +w perm: /home/newusername, dir owned by 0:0 mode=0755)
Dec 30 19:03:42 mydomain dovecot: lda(newusername): Fatal: Invalid user settings. Refer to server log for more information.
Dec 30 19:03:42 mydomain postfix/local[8123]: A22E78221C13: to=<newusername@localhost.com>, orig_to=<newusername@localhost>, relay=local, delay=0.15, delays=0.06/0.02/0/0.07, dsn=4.3.0, status=deferred (temporary failure)

編輯:

然後我跑了sudo chown -R newusername:newusername /home/newusername,然後又重複了一次,sudo echo "TEST" | sudo mail -s "testmail" newuser@localhost && sudo tail -f /var/log/maillog但仍然出現以下錯誤:

Dec 30 20:42:29 mydomain postfix/qmgr[8094]: E0DF28221C14: from=<anotherusername@mydomain.com>, size=463, nrcpt=1 (queue active)
Dec 30 20:42:29 mydomain dovecot: lda(newusername): Error: user newusername: Initialization failed: Namespace '': mkdir(/home/newusername/Maildir) failed: Permission denied (euid=1001(newusername) egid=1001(newusername) missing +w perm: /home/newusername, UNIX perms appear ok (ACL/MAC wrong?))
Dec 30 20:42:29 mydomain dovecot: lda(newusername): Fatal: Invalid user settings. Refer to server log for more information.
Dec 30 20:42:29 mydomain postfix/local[8531]: E0DF28221C14: to=<newusername@localhost.com>, orig_to=<newusername@localhost>, relay=local, delay=1101, delays=1101/0.02/0/0.06, dsn=4.3.0, status=deferred (temporary failure)
Dec 30 20:45:40 mydomain postfix/pickup[8529]: CF3CB80B33C4: uid=0 from=<root>
Dec 30 20:45:40 mydomain postfix/cleanup[8551]: CF3CB80B33C4: message-id=<20141231014540.CF3CB80B33C4@mydomain.com>
Dec 30 20:45:40 mydomain postfix/qmgr[8094]: CF3CB80B33C4: from=<root@mydomain.com>, size=455, nrcpt=1 (queue active)
Dec 30 20:45:40 mydomain dovecot: lda(newusername): Error: user newusername: Initialization failed: Namespace '': mkdir(/home/newusername/Maildir) failed: Permission denied (euid=1001(newusername) egid=1001(newusername) missing +w perm: /home/newusername, UNIX perms appear ok (ACL/MAC wrong?))
Dec 30 20:45:40 mydomain dovecot: lda(newusername): Fatal: Invalid user settings. Refer to server log for more information.
Dec 30 20:45:40 mydomain postfix/local[8553]: CF3CB80B33C4: to=<newusername@localhost.com>, orig_to=<newusername@localhost>, relay=local, delay=0.15, delays=0.08/0.02/0/0.05, dsn=4.3.0, status=deferred (temporary failure)

回答:

這個問題是由 SELinux 造成的。我通過sudo nano /etc/sysconfig/selinux然後設置解決了問題SELINUX=disabled。這在開發過程中是可以接受的。一個更完整的解決方案是設置一個 SELinux 規則,允許 postfix 和 dovecot 在其投入生產之前執行。

注意:七百四十二建議我檢查 SELinux 狀態,所以我將他標記為正確答案。

關鍵在這裡:failed: Permission denied (euid=1001(newusername) egid=1001(newusername) missing +w perm: /home/newusername, dir owned by 0:0 mode=0755

Dovecot 正在嘗試以/home/newusername/{whatever your maildir is}newusername:newusername 的身份寫入,但是,該目錄歸使用者 0:0 (root) 所有。因為權限模式是755,所以只有擁有者有+w權限

此外,如果您使用 SELinux,請確保您的 ACL 允許 dovecot 寫入您的郵件目錄

我遇到了同樣的問題。家長還提到它通過禁用 selinux 使其工作。謝謝你的提示。禁用 SEL 不是我的選擇。

因此,如果您不想禁用 selinux,請嘗試:

  • 檢查“問題”目錄的 SELinux 上下文:
ls -Z /home/newusername
drwx------. centos       centos       unconfined_u:object_r:user_home_dir_t:s0 centos
drwx------. newusername  newusername  unconfined_u:object_r:home_root_t:s0 newusername
  • 它應該顯示user_home_dir_t為上下文
  • 它不應該是home_root_tselinux 上下文。

***觀察:***如果您以 root 身份創建 homedir,它將獲取根上下文,然後使用者創建的每個對像都將具有根上下文。

  • 修復此執行:
restorecon -vR /home/newuserhome
  • 再次檢查 SELinux 上下文,你現在應該有:
ls -Z /home/newusername
drwx------. centos       centos       unconfined_u:object_r:user_home_dir_t:s0 centos
drwx------. newusername  newusername  unconfined_u:object_r:user_home_dir_t:s0 newusername
  • **測試:**嘗試在內部創建文件或目錄newuserhome並檢查 SEL 上下文
  • 如果新文件仍然沒有顯示正確的上下文執行:
semanage fcontext -a -e /home /home/newusername
restorecon -vR /home/newuserhome

希望它現在應該為“正常”主目錄提供適當的上下文並允許訪問。

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