max*_*max 7 linux selinux centos-6
我正在尝试更改上传目录的 selinux 上下文以启用匿名上传。
这是目录路径 /var/ftp/upload
这是默认上下文
[root@server ftp]# ls -Z 上传 drwxr-xr-x。root root unconfined_u:object_r:public_content_t:s0 上传
我试过这个命令来改变目录的类型
[root@server ftp]# semanage fcontext -a -t public_content_rw_t 上传
[root@server ftp]# restorecon -v 上传
它没有改变,这里有什么错误?
[root@server ftp]# ls -Z pub drwxr-xr-x。root root unconfined_u:object_r:public_content_t:s0 上传
semange 和 chcon 之间的区别在于,如果系统被重新标记,则 chcon 是“临时的”,文件/目录中存在的上下文将丢失,使用 semanage 使 selinux 上下文持久化。
为了使 semanage 工作,您必须提供文件或目录的完整路径,这就是为什么semanage fcontext -a -t public_content_rw_t upload/不起作用但起作用的原因
semanage fcontext -a -t public_content_rw_t "/var/ftp/upload(/.*)?;restorecon 不需要完整路径。
这是默认上下文
[root@服务器ftp]# ll -Zd上传/ drwxr-xr-x。root root unconfined_u:object_r:public_content_t:s0 上传/
我尝试使用此命令来更改上下文
[root@server ftp]# semanage fcontext -a -t public_content_rw_t upload/ [root@服务器ftp]# ll -Zd上传/ drwxr-xr-x。root root unconfined_u:object_r:public_content_t:s0 上传/
[root@server ftp]# Restorecon -R -v 上传 [root@服务器ftp]# ll -Zd上传/ drwxr-xr-x。root root unconfined_u:object_r:public_content_t:s0 上传/
它不起作用,但此命令会将上下文写入/etc/selinux/targeted/contexts/files/file_contexts.local文件中
看这里
# 该文件由 libsemanage 自动生成 # 不要直接编辑。 上传/ system_u:object_r:public_content_rw_t:s0
现在我尝试了这个命令(工作命令)
[root@server ftp]# semanage fcontext -a -t public_content_rw_t "/var/ftp/upload(/.*)?"
[root@server ftp]# Restorecon -R -v 上传 Restorecon 重置 /var/ftp/upload 上下文 unconfined_u:object_r:public_content_t:s0->unconfined_u:object_r:public_content_rw_t:s0
现在上下文已经改变了。 [root@服务器ftp]# ll -Zd上传/ drwxr-xr-x。root root unconfined_u:object_r:public_content_rw_t:s0 上传/
但我真的不知道为什么它会起作用,看看命令的差异。
我在手册页中得到了答案man ftpd_selinux
语义 fcontext -a -t public_content_rw_t "/var/ftpd/incoming(/.*)?"