이 튜토리얼은 CentOS 서버에서 SELinux(Security-Enhanced Linux)를 비활성화하는 방법을 보여준다. CentOS 버전은 7 또는 8이어야 한다. 버전은 중요하지 않다.

SELinux란 무엇인가?

SELinux는 커널이 직접 제어하는 보안 메커니즘이다. 관리자와 사용자가 SELinux 정책에 기반한 접근 제어에 대해 더 많은 통제권을 가질 수 있게 한다.

SELinux에는 세 가지 작동 모드가 있다:

  1. Enforcing: SELinux 정책과 정책 규칙에 기반한 접근을 허용한다.
  2. Permissive: SELinux는 Enforcing 모드에서 실행 중이었다면 거부되었을 작업만 로깅한다.
  3. Disabled: 메시지가 로깅되지 않으며 서버에 SELinux 정책이 더 이상 활성화되지 않는다. 대부분의 경우 Disabled 모드는 cPanel이나 Plesk와 같은 웹 제어판에서 사용된다.

사전 요구사항

root 사용자 또는 sudo 권한이 있는 사용자만 SELinux 모드를 업데이트할 수 있다.

SELinux 모드 확인하기

"sestatus" 명령으로 SELinux 상태를 확인할 수 있다. 출력은 SELinux가 활성화되어 있고 모드가 Enforcing으로 설정되어 있음을 보여준다.

SELinux status:                 enabled
SELinuxfs mount:                /sys/fs/selinux
SELinux root directory:         /etc/selinux
Loaded policy name:             targeted
Current mode:                   enforcing
Mode from config file:          enforcing
Policy MLS status:              enabled
Policy deny_unknown status:     allowed
Memory protection checking:     actual (secure)
Max kernel policy version:      31

SELinux 비활성화하기

모드를 Permissive로 변경하는 것을 강력히 권장한다. 때로는 일부 애플리케이션이 SELinux를 좋아하지 않아 Disabled 모드를 요구하는 경우가 있다.

SELinux 모드를 Enforcing에서 Disabled로 영구적으로 변경하려면, 먼저 vi 또는 nano와 같은 텍스트 편집기를 사용해야 한다.

/etc/selinux/config 파일을 열고 6번째 줄의 SELINUX 값을 disabled로 변경한다:

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#  enforcing - SELinux security policy is enforced.
#  permissive - SELinux prints warnings instead of enforcing.
#  disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these three values:
# targeted - Targeted processes are protected,
#  minimum - Modification of targeted policy. Only selected processes are protected. 
#  mls - Multi Level Security protection.
SELINUXTYPE=targeted

이제 파일을 저장하고 텍스트 편집기를 종료한다. 서버를 재부팅할 시간이다:

sudo reboot

SELinux 상태 최종 확인

이제 서버에서 SELinux가 성공적으로 비활성화되었는지 확인해야 한다. "sestatus" 명령을 다시 실행하면 출력은 다음과 같아야 한다:

SELinux status:                 disabled

결론

이제 적합하거나 필요한 SELinux 모드로 변경할 수 있다. SELinux는 강제 접근 제어(MAC)를 구현하는 보안 메커니즘이다. SELinux는 CentOS7 및 CentOS8 시스템에서 기본적으로 Enforcing 모드로 제공된다. 구성 파일을 편집하고 서버를 재부팅하여 수정할 수 있다.

CentOS SELinux 페이지에서 SELinux에 대한 더 많은 정보를 확인할 수 있다.