在 CentOS 里提到 “context”,通常是指 SELinux 的安全上下文(security context)。下面分几种常见场景说明如何“重置”。
restorecon(推荐)# 重置单个文件
restorecon -v /path/to/file
# 重置目录及其内容
restorecon -Rv /path/to/dir
-R:递归
-v:显示过程
适用于:文件被手动改过 context,或拷贝文件后 context 不正确
restorecon 无效(策略未定义)可能是该路径没有默认 context,可先查看:
semanage fcontext -l | grep /path
touch /.autorelabel
reboot
系统重启后会自动重新标记所有文件。
⚠️ 大系统可能耗时较长
fixfiles onboot
# 或
fixfiles restore
ls -Z /path/to/file
ps -Z # 进程
chcon -t httpd_sys_content_t /var/www/html/index.html
semanage fcontext -a -t httpd_sys_content_t "/data(/.*)?"
restorecon -Rv /data
请补充一下:
我可以给你更精确的操作步骤。