user_home_t
type:
~]$
touch file1
~]$
ls -Z file1
-rw-rw-r-- user1 group1 unconfined_u:object_r:user_home_t:s0 file1
/etc/
, the new file is created in accordance to default-labeling rules for /etc/
. Copying a file (without additional options) may not preserve the original context:
~]$
ls -Z file1
-rw-rw-r-- user1 group1 unconfined_u:object_r:user_home_t:s0 file1
~]#
cp file1 /etc/
~]$
ls -Z /etc/file1
-rw-r--r-- root root unconfined_u:object_r:etc_t:s0 /etc/file1
file1
is copied to /etc/
, if /etc/file1
does not exist, /etc/file1
is created as a new file. As shown in the example above, /etc/file1
is labeled with the etc_t
type, in accordance to default-labeling rules.
cp
options to preserve the context of the original file, such as --preserve=context
. SELinux policy may prevent contexts from being preserved during copies.
Procedure 10.16. Copying Without Preserving SELinux Contexts
cp
command, if no options are given, the type is inherited from the targeted, parent directory.
user_home_t
type:
~]$
touch file1
~]$
ls -Z file1
-rw-rw-r-- user1 group1 unconfined_u:object_r:user_home_t:s0 file1
/var/www/html/
directory is labeled with the httpd_sys_content_t
type, as shown with the following command:
~]$
ls -dZ /var/www/html/
drwxr-xr-x root root system_u:object_r:httpd_sys_content_t:s0 /var/www/html/
file1
is copied to /var/www/html/
, it inherits the httpd_sys_content_t
type:
~]#
cp file1 /var/www/html/
~]$
ls -Z /var/www/html/file1
-rw-r--r-- root root unconfined_u:object_r:httpd_sys_content_t:s0 /var/www/html/file1
Procedure 10.17. Preserving SELinux Contexts When Copying
--preserve=context
option to preserve contexts when copying.
user_home_t
type:
~]$
touch file1
~]$
ls -Z file1
-rw-rw-r-- user1 group1 unconfined_u:object_r:user_home_t:s0 file1
/var/www/html/
directory is labeled with the httpd_sys_content_t
type, as shown with the following command:
~]$
ls -dZ /var/www/html/
drwxr-xr-x root root system_u:object_r:httpd_sys_content_t:s0 /var/www/html/
--preserve=context
option preserves SELinux contexts during copy operations. As shown below, the user_home_t
type of file1
was preserved when the file was copied to /var/www/html/
:
~]#
cp --preserve=context file1 /var/www/html/
~]$
ls -Z /var/www/html/file1
-rw-r--r-- root root unconfined_u:object_r:user_home_t:s0 /var/www/html/file1
Procedure 10.18. Copying and Changing the Context
--context
option to change the destination copy's context. The following example is performed in the user's home directory:
user_home_t
type:
~]$
touch file1
~]$
ls -Z file1
-rw-rw-r-- user1 group1 unconfined_u:object_r:user_home_t:s0 file1
--context
option to define the SELinux context:
~]$
cp --context=system_u:object_r:samba_share_t:s0 file1 file2
--context
, file2
would be labeled with the unconfined_u:object_r:user_home_t
context:
~]$
ls -Z file1 file2
-rw-rw-r-- user1 group1 unconfined_u:object_r:user_home_t:s0 file1 -rw-rw-r-- user1 group1 system_u:object_r:samba_share_t:s0 file2
Procedure 10.19. Copying a File Over an Existing File
file1
in the /etc/
directory. As shown below, the file is labeled with the etc_t
type:
~]#
touch /etc/file1
~]$
ls -Z /etc/file1
-rw-r--r-- root root unconfined_u:object_r:etc_t:s0 /etc/file1
file2
, in the /tmp/
directory. As shown below, the file is labeled with the user_tmp_t
type:
~]$
touch /tmp/file2
~$
ls -Z /tmp/file2
-rw-r--r-- root root unconfined_u:object_r:user_tmp_t:s0 /tmp/file2
file1
with file2
:
~]#
cp /tmp/file2 /etc/file1
file1
labeled with the etc_t
type, not the user_tmp_t
type from /tmp/file2
that replaced /etc/file1
:
~]$
ls -Z /etc/file1
-rw-r--r-- root root unconfined_u:object_r:etc_t:s0 /etc/file1
Important