This is the default context
[root@server ftp]# ll -Zd upload/
drwxr-xr-x. root root unconfined_u:object_r:public_content_t:s0 upload/
I tried this command to change the context
[root@server ftp]# semanage fcontext -a -t public_content_rw_t upload/
[root@server ftp]# ll -Zd upload/
drwxr-xr-x. root root unconfined_u:object_r:public_content_t:s0 upload/
[root@server ftp]# restorecon -R -v upload
[root@server ftp]# ll -Zd upload/
drwxr-xr-x. root root unconfined_u:object_r:public_content_t:s0 upload/
It's not working, but this command will write the context in /etc/selinux/targeted/contexts/files/file_contexts.local
file
see here
# This file is auto-generated by libsemanage
# Do not edit directly.
upload/ system_u:object_r:public_content_rw_t:s0
Now I tried this command (Working Command)
[root@server ftp]# semanage fcontext -a -t public_content_rw_t "/var/ftp/upload(/.*)?"
[root@server ftp]# restorecon -R -v upload
restorecon reset /var/ftp/upload context unconfined_u:object_r:public_content_t:s0->unconfined_u:object_r:public_content_rw_t:s0
Now context is changed.
[root@server ftp]# ll -Zd upload/
drwxr-xr-x. root root unconfined_u:object_r:public_content_rw_t:s0 upload/
But I really don't no why it's working, see the difference in command.
I got the answer in the man page of man ftpd_selinux
semanage fcontext -a -t public_content_rw_t "/var/ftpd/incoming(/.*)?"