Red Hat Training
A Red Hat training course is available for Red Hat Enterprise Linux
4.10.3. 기본 SELinux 컨텍스트 확인
matchpathcon
유틸리티를 사용하여 파일과 디렉터리의 SELinux 컨텍스트가 올바른지 확인합니다. 이 유틸리티는 시스템 정책을
쿼리한 다음 파일 경로와 연결된 기본 보안 컨텍스트를 제공합니다.[6] 다음 예제에서는 matchpathcon 을 사용하여 /var/www/html/
디렉토리의 파일에 올바르게 레이블이 지정되어 있는지 확인하는 방법을 보여줍니다.
절차 4.16. matchpathcon
을 사용하여 기본 SELinux Conxtext 확인
- root 사용자로
/var/www/html/
디렉터리에 3개의 파일(file1
, file2
및 file/var/www/html/
:에서httpd_sys_content_t
유형을 상속받습니다.~]#
touch /var/www/html/file{1,2,3}~]#
ls -Z /var/www/html/ -rw-r--r-- root root unconfined_u:object_r:httpd_sys_content_t:s0 file1 -rw-r--r-- root root unconfined_u:object_r:httpd_sys_content_t:s0 file2 -rw-r--r-- root root unconfined_u:object_r:httpd_sys_content_t:s0 file3 - root로
file1
유형을samba_share_t
로 변경합니다. Apache HTTP 서버는samba_share_t
유형으로 레이블이 지정된 파일 또는 디렉터리를 읽을 수 없습니다.~]#
chcon -t samba_share_t /var/www/html/file1 matchpathcon
-V
옵션은 현재 SELinux 컨텍스트를 SELinux 정책의 올바른 기본 컨텍스트와 비교합니다. 다음 명령을 입력하여/var/www/html/
디렉터리에 있는 모든 파일을 확인합니다.~]$
matchpathcon -V /var/www/html/* /var/www/html/file1 has context unconfined_u:object_r:samba_share_t:s0, should be system_u:object_r:httpd_sys_content_t:s0 /var/www/html/file2 verified. /var/www/html/file3 verified.
matchpathcon 명령의 다음 출력은
file1
이 samba_share_t 유형으로 레이블이 지정되어 있지만 httpd_
sys_content_t
유형으로 레이블이 지정되어야 한다고 설명합니다.
/var/www/html/file1 has context unconfined_u:object_r:samba_share_t:s0, should be system_u:object_r:httpd_sys_content_t:s0
레이블 문제를 해결하고 root로
file1
에 대한 Apache HTTP Server 액세스를 허용하려면 restorecon
유틸리티를 사용합니다.
~]#
restorecon -v /var/www/html/file1
restorecon reset /var/www/html/file1 context unconfined_u:object_r:samba_share_t:s0->system_u:object_r:httpd_sys_content_t:s0