2017-05-09 9 views
0

내 CentOS 시스템을 구성하기 위해 타임 스탬프와 내용 이외의 거의 모든 속성을 보존하는 임의의 파일을 덮어 쓰고 싶습니다.CentOS7 : 파일 복사 및 SELinux 컨텍스트 유지

예를 들어, 내가 /etc/phpMyAdmin/config.inc.php

주를 사용합니다 : 파일을 복사하는 것은 내가 http://localhost/phpmyadmin 시도 다른 파일 시스템

[[email protected] phpMyAdmin]# ls -laZ /etc/phpMyAdmin/ 
drwxr-x---. root apache system_u:object_r:etc_t:s0  . 
drwxr-xr-x. root root system_u:object_r:etc_t:s0  .. 
-rw-r-----. root apache system_u:object_r:etc_t:s0  config.inc.php 
[[email protected] phpMyAdmin]# /bin/cp -frv --backup=numbered --preserve=mode,ownership,context,xattr config.inc.php /etc/phpMyAdmin/config.inc.php 
«config.inc.php» -> «/etc/phpMyAdmin/config.inc.php» (respaldo: «/etc/phpMyAdmin/config.inc.php.~1~») 
[[email protected] phpMyAdmin]# ls -laZ /etc/phpMyAdmin/ 
drwxr-x---. root apache system_u:object_r:etc_t:s0  . 
drwxr-xr-x. root root system_u:object_r:etc_t:s0  .. 
-rw-r-----. root apache system_u:object_r:unlabeled_t:s0 config.inc.php 
-rw-r-----. root apache system_u:object_r:etc_t:s0  config.inc.php.~1~ 
[[email protected] phpMyAdmin]# systemctl restart httpd 

에, 주먹 시간이 나는 '을 수 SELinux에 경고를 받고, 아파치 파일에 액세스하지 마십시오.

[[email protected] phpMyAdmin]# chcon --reference /etc/phpMyAdmin/config.inc.php.~1~ /etc/phpMyAdmin/config.inc.php 
[[email protected] phpMyAdmin]# ls -laZ /etc/phpMyAdmin/ 
drwxr-x---. root apache system_u:object_r:etc_t:s0  . 
drwxr-xr-x. root root system_u:object_r:etc_t:s0  .. 
-rw-r-----. root apache system_u:object_r:etc_t:s0  config.inc.php 
-rw-r-----. root apache system_u:object_r:etc_t:s0  config.inc.php.~1~ 
[[email protected] phpMyAdmin]# systemctl restart httpd 

이제 아파치에서 파일을 읽을 수 있습니다.

어떻게하면 원본 파일의 SELinux 컨텍스트를 유지할 수 있습니까?

답변

0

cp 설명서에 따르면 스위치 "--preserve = context"를 사용하면 프로세스 중에 Selinux 컨텍스트를 복사 할 수 있습니다.

는 레드햇에서이 우수한 문서를 보려면 다음을 보면, 그것은 멋지고 인간의 언어로 항목을 설명합니다

https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Security-Enhanced_Linux/sect-Security-Enhanced_Linux-Working_with_SELinux-Maintaining_SELinux_Labels_.html

+0

내가 많은 CP 옵션을 (그 링크에 표시), 시도했습니다 - preserve = context 및 --no-preserve = context이지만 결과는 항상 같으며 apache는 파일을 사용할 수 없으며 ** unlabeled_t ** 속성이 설정됩니다. 복사 아파치가 파일을 사용할 수있을 때만 chcon을 사용하십시오. 아마도 cp의 버그일까요? –

+0

안녕하세요 Carlos 님, 다른 파일 시스템의 대상 파일입니까? 어떤 파일 시스템 유형입니까? 볼륨을 어디에 마운트합니까? –

+0

소스 파일 시스템은/mnt/shared에 마운트 된 ext4입니다. 대상 (루트) 파일 시스템은 ext3입니다. –