• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

restorecon Command Examples in Linux

by admin

Using restorecon is easy. Just type restorecon, followed by the name of the file that you need to change. Once again, I’ve changed the context of the index.html file back to the home directory type. This time, though, I’m using restorecon to set the correct type:

$ ls -Z
-rw-rw-r--. web web unconfined_u:object_r:user_home_t:s0 index.html
$ sudo restorecon index.html
$ ls -Z
-rw-rw-r--. web web unconfined_u:object_r:httpd_sys_content_t:s0 index.html

And that’s all there is to it.

The restorecon command is a part of the policycoreutil package, so in order to use this command, this package should be installed on the system.

restorecon Command Examples

1. To restore files default SELinux security contexts:

# restorecon 

2. To ignore the files that do not exists:

# restorecon -i 

3. To specify the directory to be excluded:

# restorecon -e /var 

4. To change the files and directories file labels recursuively:

# restorecon -r
# restorecon -R 

5. To not to change any file labels:

# restorecon -n 

6. To save list of files with incorrect context in outfilename:

# restorecon -o /tmp/file 

7. To show progress by printing * every 1000 files:

# restorecon -p 

8. To show changes in file labels:

# restorecon -v 

9. To show changes in file labels, with type, role, or user are changing:

# restorecon -vv 

10. To force reset of context to match file_context for customizable files:

# restorecon -F 

Conclusion

Using the restorecon command is the most popular and preferred way of modifying the SELinux context of a file or directory. As is visible from the name of the restorecon command, it is used to restore the default context of a file or directory by reading the default rules set in the SELinux policy. If the wrong context is applied, restorecon automatically corrects it from the policy of the filesystem.

Filed Under: Linux

Some more articles you might also be interested in …

  1. The System Continuously Displayed the Error Message from the “avahi-demon” in /var/log/messages
  2. “btrfs” command examples to Create and Manage Btrfs File System
  3. Unable To Boot Up Linux OS with Auditd (CentOS/RHEL)
  4. How to configure iSCSI Initiator (client) in CentOS / RHEL 7
  5. pinky Command Examples in Linux
  6. nohup Command Options in Linux
  7. Beginners Guide to MySQL User Management
  8. How to List and Set SELinux Context for MySQL Server
  9. Basic nano Commands (Cheat Sheet)
  10. How to Set External Network For Containers in Linux Containers (LXC)

You May Also Like

Primary Sidebar

Recent Posts

  • vgextend Command Examples in Linux
  • setpci command – configure PCI device
  • db_load command – generate db database
  • bsdtar command – Read and write tape archive files

© 2022 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright