Red Hat Training
A Red Hat training course is available for Red Hat Enterprise Linux
13.4.3. 서비스 간 파일 공유
type Enforcement를 사용하면 프로세스가 다른 프로세스에서 사용할 파일에 액세스하는 것을 방지할 수 있습니다. 예를 들어 Samba는 기본적으로 Apache HTTP 서버에서 사용하기 위한
httpd_sys_content_t
유형으로 레이블이 지정된 파일을 읽을 수 없습니다. 필요한 파일에 public_content_ t 또는 public_content_rw_t
유형으로 레이블이 지정된 경우 Apache HTTP Server, FTP, rsync 및 Samba 간에 파일을 공유할 수 있습니다.
다음 예제에서는 디렉터리와 파일을 만들고 Apache HTTP 서버, FTP, rsync 및 Samba를 통해 해당 디렉토리와 파일을 공유(읽기 전용)할 수 있습니다.
mkdir
유틸리티를 root로 사용하여 여러 서비스 간에 파일을 공유할 새 최상위 디렉토리를 생성합니다.~]# mkdir /shares
- file-context 구성의 패턴과 일치하지 않는 파일과 디렉터리에
default_t
유형으로 레이블이 지정될 수 있습니다. 이 유형은 제한된 서비스에 액세스할 수 없습니다.~]$ ls -dZ /shares drwxr-xr-x root root unconfined_u:object_r:default_t:s0 /shares
- root로
/shares/index.html
파일을 만듭니다. 다음 콘텐츠를 복사하여/shares/index.html에 붙여넣습니다.
<html> <body> <p>Hello</p> </body> </html>
public_content_t
유형으로/shares/
레이블을 지정하면 Apache HTTP 서버, FTP, rsync 및 Samba의 읽기 전용 액세스만 허용됩니다. root로 다음 명령을 입력하여 레이블 변경 사항을 파일 컨텍스트 구성에 추가합니다.~]# semanage fcontext -a -t public_content_t "/shares(/.*)?"
restorecon
유틸리티를 root로 사용하여 라벨 변경 사항을 적용합니다.~]# restorecon -R -v /shares/ restorecon reset /shares context unconfined_u:object_r:default_t:s0->system_u:object_r:public_content_t:s0 restorecon reset /shares/index.html context unconfined_u:object_r:default_t:s0->system_u:object_r:public_content_t:s0
Samba를 통해
/shares/
를 공유하려면 다음을 수행합니다.
- samba, samba -common 및 samba-client 패키지가 설치되어 있는지 확인합니다(버전 번호가 다를 수 있음).
~]$ rpm -q samba samba-common samba-client samba-3.4.0-0.41.el6.3.i686 samba-common-3.4.0-0.41.el6.3.i686 samba-client-3.4.0-0.41.el6.3.i686
이러한 패키지가 설치되어 있지 않으면 root로 다음 명령을 실행하여 설치합니다.~]# yum install package-name
/etc/samba/smb.conf
파일을 root로 편집합니다. 다음 항목을 이 파일의 맨 아래에 추가하여 Samba를 통해/shares/
디렉토리를 공유합니다.[shares] comment = Documents for Apache HTTP Server, FTP, rsync, and Samba path = /shares public = yes writable = no
- Samba 파일 시스템을 마운트하려면 Samba 계정이 필요합니다. root로 다음 명령을 입력하여 Samba 계정을 만듭니다. 여기서 username 은 기존 Linux 사용자입니다. 예를 들어 smbpasswd -a testuser 는 Linux
testuser
사용자에 대한 Samba 계정을 만듭니다.~]# smbpasswd -a testuser New SMB password: Enter a password Retype new SMB password: Enter the same password again Added user testuser.
위의 명령을 실행하면 시스템에 없는 계정의 사용자 이름을 지정하면'username'! 오류에 대한 Unix 계정을 찾을 수 없습니다
. - Samba 서비스를 시작합니다.
~]# systemctl start smb.service
- 다음 명령을 입력하여 사용 가능한 공유를 나열합니다. 여기서 username 은 3단계에 추가된 Samba 계정입니다. 암호를 입력하라는 메시지가 표시되면 3단계에서 Samba 계정에 할당된 암호를 입력합니다(버전 번호는 다를 수 있음).
~]$ smbclient -U username -L localhost Enter username's password: Domain=[HOSTNAME] OS=[Unix] Server=[Samba 3.4.0-0.41.el6] Sharename Type Comment --------- ---- ------- shares Disk Documents for Apache HTTP Server, FTP, rsync, and Samba IPC$ IPC IPC Service (Samba Server Version 3.4.0-0.41.el6) username Disk Home Directories Domain=[HOSTNAME] OS=[Unix] Server=[Samba 3.4.0-0.41.el6] Server Comment --------- ------- Workgroup Master --------- -------
mkdir
유틸리티를 사용하여 새 디렉토리를 만듭니다. 이 디렉토리는 Samba공유를
마운트하는 데 사용됩니다.~]# mkdir /test/
- 다음 명령을 루트로 입력하여 Samba
공유를
/test/
에 마운트하고 username 을 3단계의 사용자 이름으로 바꿉니다.~]# mount //localhost/shares /test/ -o user=username
3단계에 구성된 사용자 이름의 암호를 입력합니다. - Samba를 통해 공유되는 파일의 내용을 확인합니다.
~]$ cat /test/index.html <html> <body> <p>Hello</p> </body> </html>
Apache HTTP 서버를 통해
/shares/
를 공유하려면 다음을 수행합니다.
- httpd 패키지가 설치되었는지 확인합니다 (버전 번호는 다를 수 있음).
~]$ rpm -q httpd httpd-2.2.11-6.i386
이 패키지가 설치되지 않은 경우yum
유틸리티를 root로 사용하여 설치합니다.~]# yum install httpd
/var/www/html/
디렉터리로 변경합니다. root로 다음 명령을 입력하여/shares/
디렉터리에 링크(이름이 지정된공유
)를 생성합니다.html]# ln -s /shares/ shares
- Apache HTTP 서버를 시작합니다.
~]# systemctl start httpd.service
- 웹 브라우저를 사용하여
http://localhost/shares
로 이동합니다./shares/index.html
파일이 표시됩니다.
기본적으로 Apache HTTP 서버는
index.html
파일이 있는 경우 해당 파일을 읽습니다. /shares/
에 index.html
이 없고 대신 file1, file
2 및 file
3
이 있는 경우 http://localhost/shares
에 액세스할 때 디렉토리 목록이 발생했습니다.
index.html
파일을 제거합니다.~]# rm -i /shares/index.html
touch
유틸리티를 루트로 사용하여/shares/
에 세 개의 파일을 생성합니다.~]# touch /shares/file{1,2,3} ~]# ls -Z /shares/ -rw-r--r-- root root system_u:object_r:public_content_t:s0 file1 -rw-r--r-- root root unconfined_u:object_r:public_content_t:s0 file2 -rw-r--r-- root root unconfined_u:object_r:public_content_t:s0 file3
- root로 다음 명령을 입력하여 Apache HTTP Server의 상태를 확인합니다.
~]# systemctl status httpd.service httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled) Active: inactive (dead)
서버가 중지되면 시작합니다.~]# systemctl start httpd.service
- 웹 브라우저를 사용하여
http://localhost/shares
로 이동합니다. 디렉터리 목록이 표시됩니다.