
我有一個用戶$USER
,它是具有授權用戶文件的系統用戶帳戶。當我啟用 SELinux 時,我無法使用公鑰 ssh 進入伺服器。如果我setenabled 0
現在$USER
可以登入。
我應該更改什麼 SELinux bool/policy 來糾正此行為而不完全停用 SELinux?
值得注意的是,$USER
可以在此預設 SELinux 配置下使用密碼登錄,我希望了解這裡發生的情況以及為什麼 SELinux 不阻止這種情況。 (解決此問題後我將完全停用密碼身份驗證,因此更高興知道這個問題)
答案1
假設 ~/.ssh/* 上的檔案系統權限正確,然後檢查輸出
sealert -a /var/log/audit/audit.log
AVC 條目中應該有線索。解決方案很可能歸結為運行:
restorecon -R -v ~/.ssh
答案2
如果sealert
系統上缺少該文件,就像我最近遇到的系統一樣,也有可能audit2allow
:
$ sudo audit2allow -w -a
type=AVC msg=audit(1548909218.552:1037): avc: denied { read } for pid=13996 comm="sshd" name="authorized_keys" dev="dm-0" ino=4663556 scontext=system_u:system_r:sshd_t:s0-s0:c0.c1023 tcontext=system_u:object_r:admin_home_t:s0 tclass=file
Was caused by:
Missing type enforcement (TE) allow rule.
You can use audit2allow to generate a loadable module to allow this access.
分解 AVC:
avc: denied { read } for pid=13996 comm="sshd" name="authorized_keys" dev="dm-0" ino=4663556
"sshd" was denied read on a file resource named "authorized_keys".
scontext=system_u:system_r:sshd_t:s0-s0:c0.c1023
SELinux context of the sshd process that attempted the denied action.
tcontext=system_u:object_r:admin_home_t:s0 tclass=file
SELinux context of the authorized_keys file.
儘管audit2allow沒有簡潔地告訴如何解決問題,但透過查看scontext
和tcontext
,該scontext
值指示所需的上下文,同時tcontext
顯示不令人滿意的「authorized_keys」文件上下文。
在這種情況下,restorecon -R -v ~/.ssh
它本身不起作用,但應用所需的上下文可以:
$ sudo semanage fcontext --add -t ssh_home_t "/path/to/my/.ssh(/.*)?"; \
$ sudo restorecon -FRv /path/to/my/.ssh
根據需要,根據 AVC 中看到的內容更改資源名稱和/或上下文。此答案中的精確細節是為了解決與“authorized_keys”相關的問題而構建的,但即使sealert
或生成的 AVC 中指示了不同的文件或上下文,解決方案也可以遵循此模型audit2allow
。