cancel
Showing results for 
Search instead for 
Did you mean: 
Trevor
Starfighter Starfighter
Starfighter
  • 387 Views

SELinux File Label Change

Jump to solution

Write the command that will change the SELinux context type of 
the file /tmp/monkey, from user_tmp_t to  dhcp_etc_t.

 

Trevor "Red Hat Evangelist" Chandler
1 Solution

Accepted Solutions
Tracy_Baker
Starfighter Starfighter
Starfighter
  • 353 Views

Now this kind of depends on wht you're shooting for. If you just want to change the context type on the one file, you can do this:

# chcon -t dhcp_etc_t /tmp/monkey

However, by using chcon, the possibility exists that the context will revert if/when the filesystem is relabeled.

Now, if you have a set of files that you want a specific context and you want new files to automatically get the context, you'd:

  1. Create a directory: $ mkdir -v /tmp/my_files
  2. Set the SELinux policy on the directory:
    $ sudo semanage fcontext -a -t dhcp_etc_t '/tmp/my_files(/.*)?'
  3. Apply the context to the directory and an files in the directory:
    $ sudo restorecon -Rv /tmp/my_files
Program Lead at Arizona's first Red Hat Academy, est. 2005
Estrella Mountain Community College

View solution in original post

3 Replies
Tracy_Baker
Starfighter Starfighter
Starfighter
  • 354 Views

Now this kind of depends on wht you're shooting for. If you just want to change the context type on the one file, you can do this:

# chcon -t dhcp_etc_t /tmp/monkey

However, by using chcon, the possibility exists that the context will revert if/when the filesystem is relabeled.

Now, if you have a set of files that you want a specific context and you want new files to automatically get the context, you'd:

  1. Create a directory: $ mkdir -v /tmp/my_files
  2. Set the SELinux policy on the directory:
    $ sudo semanage fcontext -a -t dhcp_etc_t '/tmp/my_files(/.*)?'
  3. Apply the context to the directory and an files in the directory:
    $ sudo restorecon -Rv /tmp/my_files
Program Lead at Arizona's first Red Hat Academy, est. 2005
Estrella Mountain Community College
Chetan_Tiwary_
Community Manager
Community Manager
  • 309 Views

Thanks for explaining this so succintly @Tracy_Baker !

Trevor
Starfighter Starfighter
Starfighter
  • 301 Views

Tracy, you know I just wanted to change the context on that one file.
You just wanted to show your SELinux muscle with that extra stuff  

Thanks for saving me some keystrokes in having to type the answer.
Your use of the chcon command is what I was looking for.

 

 

Trevor "Red Hat Evangelist" Chandler
Join the discussion
You must log in to join this conversation.