Restore Selinux Default File Context
- With standard Linux permissions, these are stored with the file.
- With SELinux, the security context is also stored with the file.
- In the
extended attributessection.
- In the
- With SELinux, the security context is also stored with the file.
- Default Security Context Settings are also in the SELinux Security Policy as well.
- For example, these settings ensure that all the files in
/homehave a certain type.- If you perform
ls -lZ /home, the default Security Context isuser_home_tfor the files.- We can also change the Security Context of a file.
- No need to elevate privileges when doing this for your own files.
- If you want to change another user’s files’ Security Context, then you need to elevate privileges.
chcon -t etc_t newfile- The
etc_tis the type it is being changed to.- You will see that
user_home_thas been changed toetc_t- The Security Context database can also make changes, in this case changing back the Security Context to
user_home_trestorecon newfile.txt- If you want to reset the Security Label of every file, you need to relabel the drive.
- SELinux would restore and relabel the Security Context of each file back to what it was before.
- To perform this, we create a file in the
/directory called.autorelabeland then reboot the machine.sudo touch /.autorelabel- The next time you reboot, the Security Context of all files in the operating system will be set back to their defaults.
- Once all relabelling is done, the hidden `autorelabel` file that was created is then deleted.
- If you want the file in your home directory to have a different security context.
- And don’t want a `restorecon` or `autolabel` to reset it, you can change the policy database.
- `sudo semanage fcontext -a -t etc_t /home/user1/newfile.txt`
- `fcontext` is used for files.
- Can verify the change was added to the policy, by listing all file contexts.
-
`sudo semanage fcontext -l grep newfile.txt - Then restore the security context back with `restorecon newfile.txt`.
-
- Can verify the change was added to the policy, by listing all file contexts.
- `fcontext` is used for files.
- `sudo semanage fcontext -a -t etc_t /home/user1/newfile.txt`
- And don’t want a `restorecon` or `autolabel` to reset it, you can change the policy database.
- If you want the file in your home directory to have a different security context.
- Once all relabelling is done, the hidden `autorelabel` file that was created is then deleted.
- The next time you reboot, the Security Context of all files in the operating system will be set back to their defaults.
- To perform this, we create a file in the
- SELinux would restore and relabel the Security Context of each file back to what it was before.
- If you want to reset the Security Label of every file, you need to relabel the drive.
- The Security Context database can also make changes, in this case changing back the Security Context to
- You will see that
- The
- If you want to change another user’s files’ Security Context, then you need to elevate privileges.
- No need to elevate privileges when doing this for your own files.
- We can also change the Security Context of a file.
- If you perform
- For example, these settings ensure that all the files in