大网数据广告活动
服务器运维问答

Linux "ls -Z" shows question mark for security context

· 52CE 我爱测

I've got some files that aren't being served on a site, and assuming it was a permissions issue I ran ls -Z but keep seeing ? in place of the security context: -rw-rw-r-- pete pete ? index.cfm I get this running sudo as well. Can…

问题原文

原帖链接 · Pete · CC BY-SA 4.0

I've got some files that aren't being served on a site, and assuming it was a permissions issue I ran ls -Z but keep seeing ? in place of the security context:

-rw-rw-r--  pete pete ?                                index.cfm

I get this running sudo as well. Can anyone explain what the ? means or what I need to do to fix the file?

I've tried using sudo chcon system_u:object_r:httpd_config_t:s0 index.cfm to match the other permissions of files in the folder, but that doesn't help. Also if I try to recreate the file I get the ? again

cat index.cfm > index.bkp
sudo ls -Z
-rw-rw-r--  pete pete ?                                index.bkp
-rwxrwxrwx. pete pete system_u:object_r:httpd_config_t:s0 index.cfm
mv index.bkp index.cfm
-rw-rw-r--  pete pete ?                                index.cfm

已采纳解答

原帖链接 · xhienne · CC BY-SA 4.0

The meaning of the exclamation mark is only given in ls info page, not in its man page:

'-Z'
'--context'
'--scontext'
'--lcontext'
'--format=context'

Display the SELinux security context or '?' if none is found. '-Z' counts as format option and enables displaying of SELinux context. '--scontext' prints SELinux context left to the file name. '--lcontext' prints long format with SELinux context in the middle. '--context' prints permissions, user/group, context and file name (in comparison to '--lcontext', omits size, modification time and number of hardlinks).

Thus, this means that no security context was added to the file. And the fact that it still has no security context when you re-create the file indicates that the parent directory has no security context that can be inherited from.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2021-04-08)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。