Linux Commands - restorecon

by
Jeremy Canfield |
Updated: April 04 2020
| Linux Commands articles
The restorecon command can be used to restore a file or directory to it's default SELinux context. Files will inherit the SELinux context of the files parent directory. For example, let's say /etc/ssh has the following SELinux context.
ls -lZ /etc/ssh
drwxr-xr-x. root root system_u:object_r:etc_t:s0
If foo.txt is in the /etc/ssh directory, the restorecon command will update foo.txt to have the same SELinux context as /etc/ssh.
restorecon foo.txt
The -v (verbose) option can be used to see the SELinux context change. In this example, the SELinux context is changed from samba_share_t to etc_t.
Note: If restorecon does not make any changes, there will be no output in the console.
~]# restorecon -v foo.txt
restorecon reset foo.txt.html context unconfined_u:object_r:samba_share_t:s0->unconfined_u:object_r:etc_t:s0
Did you find this article helpful?
If so, consider buying me a coffee over at