Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am trying to change selinux context for upload directory to enable anonymous upload.

This is the Directory path /var/ftp/upload

This is the default context

[root@server ftp]# ls -Z upload
drwxr-xr-x. root root unconfined_u:object_r:public_content_t:s0 upload

I tried this command to change the type of the directory

[root@server ftp]# semanage fcontext -a -t public_content_rw_t upload
[root@server ftp]# restorecon -v upload

Its not changing, what is the mistake here ?

[root@server ftp]# ls -Z pub
drwxr-xr-x. root root unconfined_u:object_r:public_content_t:s0 upload
share|improve this question
add comment

2 Answers

Try

chcon -t public_content_rw_t /var/ftp/upload

It will work.

share|improve this answer
    
First of all it is not chcon -R , it should be chcon -t (for this particular example) and one more thing I think it is not the permanent method, now type resorecon -v upload and check it will change the context to default. –  max Nov 4 '13 at 7:30
add comment
up vote 0 down vote accepted

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(/.*)?"
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.