[ Server ][ Linux ] CentOS 7 SELinux 설정 및 해제하기 > linux

본문 바로가기
사이트 내 전체검색

linux

[ Server ][ Linux ] CentOS 7 SELinux 설정 및 해제하기

페이지 정보

작성자 웹지기 댓글 0건 조회 23,734회 작성일 18-12-13 15:17

본문

SELinux 는 Linux의 보안을 강화해 주는 보안 강화 커널이고 zero-day 공격 및 buffer overflow 등 어플리케이션 취약점으로 인한 해킹을 방지해 주는 핵심 구성요소이다.

특정 서비스가 SELinux 때문에 동작하지 않는다면 SELinux 를 끄기 보다는 해당 서비스가 SELinux 하에서 잘 동작하도록 설정을 수정하는걸 권장한다.


SELinux 동작 모드

    enforce, permissive, disable 세 가지 모드가 있으며 RHEL/CentOS 를 설치하면 default 로 enforce mode 로 동작하며 SELinux 의 rule 에 어긋나는 operation 은 거부된다.

    현재 SELinux 의 동작 모드는 sestatus 명령어로 확인할 수 있다.

    SELinux 모드 확인

# sestatus

SELinux status: enabled

SELinuxfs mount: /selinux

Current mode: enforcing

Mode from config file: enforcing

Policy version: 24

Policy from config file: targeted


    Permissive mode 는 rule 에 어긋나는 동작이 있을 경우 audit log 를 남기고 해당 operation 은 허용된다.

    개발 서버일 경우 특정 daemon 이나 서비스에 문제가 있을 경우 setenforce 0 으로 Permissive mode 로 전환하여 문제 해결후 enforce mode 로 전환하는걸 추천한다.


# setenforce 0

# sestatus

     

SELinux status: enabled

SELinuxfs mount: /selinux

Current mode: permissive

Mode from config file: enforcing

Policy version: 24

Policy from config file: targeted


SELinux 해제

    인터넷에 연결된 리눅스 서버라면 SELinux 해제는 결코 추천하지 않는다.

    해제할 경우 다시 활성화 시키려면 재부팅이 필요하며 재부팅시 모든 자원에 대해 보안 레이블을 설정해야 하므로 부팅 시간이 매우 오래 걸릴 수 있다.

vi /etc/sysconfig/selinux

SELINUX=enforcing 을 SELINUX=disabled 로 변경후 저장한다.

reboot

    SELinux 를 해제후 다시 켤 경우 relabel 이 필요하며 이때 잘못된 설정이 있을 경우 부팅이 안 되거나 ssh 로 원격 접속이 불가능할 수 있으므로 enforcing 모드가 아닌 permissive 로 설정후 재부팅하는 것을 권장한다.


File Context 보기

semanage fcontext -l|grep mysql

 
-------------------------------------------------------------------------------------------------------------------
 
표준 리눅스 보안은 임의 접근 제어(Discretionary Access Control - DAC) 모델을 따릅니다.
SELinux는 Linux 커널에 내장된 보안 모듈로 강제적 접근 제어(Mandatory Access Control - MAC)를 수행합니다.
응용프로그램에서 불필요한 부분은 제외하고 오직 필요한 기능에 대해서만 사용 권한을 안전하게 부여하는 것이 가능합니다.
따라서 사용자는 한 응용 프로그램에게 그 프로그램이 제대로 작동하는데 필요한 권한만 안전하게 부여할 수 있습니다.

OS 설치 후 SELinux는 기본적으로 적용(Enforcing) 상태로 되어있습니다.
아래 명령들을 통해 현재 서비스 상태를 확인할 수 있습니다.

[root@localhost ~]# getenforce
Enforcing
[root@localhost ~]# sestatus
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
Max kernel policy version:      28
 
SELinux가 필요하지 않은 경우 /etc/selinux/config 또는 /etc/sysconfig/selinux를 수정하여 영구적으로 비활성화 시킬 수 있습니다.
(/etc/sysconfig/selinux -> /etc/selinux/config 심볼릭 링크되어 있어 어느 파일을 편집하든 /etc/selinux/config 파일이 수정됩니다.)
 

[root@localhost ~]# ls -alh /etc/selinux/config
-rw-r--r--. 1 root root 547 Apr  6 17:59 /etc/selinux/config
[root@localhost ~]# ls -alh /etc/sysconfig/selinux
lrwxrwxrwx. 1 root root 17 Apr  6 17:59 /etc/sysconfig/selinux -> ../selinux/config
[root@localhost ~]# stat /etc/sysconfig/selinux
  File: ‘/etc/sysconfig/selinux’ -> ‘../selinux/config’
  Size: 17              Blocks: 0          IO Block: 4096   symbolic link
Device: 803h/2051d      Inode: 201612989   Links: 1
Access: (0777/lrwxrwxrwx)  Uid: (    0/    root)   Gid: (    0/    root)
Context: system_u:object_r:etc_t:s0
Access: 2017-04-17 10:46:35.397430689 +0900
Modify: 2017-04-06 17:59:38.412377900 +0900
Change: 2017-04-06 17:59:38.412377900 +0900
 Birth: -

수정을 위해 /etc/selinux/config 파일을 vi 편집기로 편집하겠습니다.
[root@localhost ~]# vi /etc/selinux/config

SELINUX=enforcing을 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 three two values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected.
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted
수정 후 시스템을 재시작해야 정상적으로 적용됩니다.

[root@localhost ~]# reboot
시스템을 바로 재시작하기 어려운 경우 setenforce 0 명령을 이용해 일시적으로 비활성화할 수 있습니다.(SELINUX=permissive)

[root@localhost ~]# setenforce 0
[root@localhost ~]# getenforce
Permissive
[root@localhost ~]# sestatus
SELinux status:                 enabled
SELinuxfs mount:                /sys/fs/selinux
SELinux root directory:         /etc/selinux
Loaded policy name:             targeted
Current mode:                   permissive
Mode from config file:          enforcing
Policy MLS status:              enabled
Policy deny_unknown status:     allowed
Max kernel policy version:      28
다시 사용이 필요한 경우 setenforce 1 명령을 이용해 활성화할 수 있습니다.(SELINUX=enforcing)

(영구적으로 활성화가 필요한 경우 /etc/selinux/config 파일에 SELINUX=enforcing으로 수정하시기 바랍니다.)

[root@localhost ~]# setenforce 1
[root@localhost ~]# getenforce
Enforcing
[root@localhost ~]# sestatus
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
Max kernel policy version:      28
각 옵션에 대한 설명은 아래를 참조하시기 바랍니다.

- When using SELINUX=enforcing,

SELinux policy is enforced, and SELinux denies access based on SELinux policy rules. Denial messages are logged.
- When using SELINUX=permissive,

SELinux policy is not enforced. SELinux does not deny access, but denials are logged for actions that would have been denied if running SELinux in enforcing mode.
- When using SELINUX=disabled,

SELinux is disabled, the SELinux module is not registered with the Linux kernel, and only DAC rules are used.

[원글링크]https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/SELinux_Users_and_Administrators_Guide/sect-Security-Enhanced_Linux-Working_with_SELinux-Main_Configuration_File.html


SELinux를 사용한다면 정책 설정이 필요합니다.

1. getsebool

getsebool BOOLEAN 또는 getsebool -a 명령을 통해 정의된 정책 및 정책 설정 상태를 확인할 수 있습니다.

[root@localhost ~]# getsebool ftpd_anon_write
ftpd_anon_write --> off
[root@localhost ~]# getsebool -a
abrt_anon_write --> off
abrt_handle_event --> off
abrt_upload_watch_anon_write --> on
antivirus_can_scan_system --> off
antivirus_use_jit --> off
 
......(중략)
 
zabbix_can_network --> off
zarafa_setrlimit --> off
zebra_write_config --> off
zoneminder_anon_write --> off
zoneminder_run_sudo --> off

2. setsebool

setsebool -P BOOLEAN on/off 명령을 통해 정책을 설정할 수 있습니다.
[root@localhost ~]# getsebool ftpd_anon_write
ftpd_anon_write --> off
[root@localhost ~]# setsebool -P ftpd_anon_write on
[root@localhost ~]# getsebool ftpd_anon_write
ftpd_anon_write --> on
SELinux는 보안 정책 설정이 복잡하고 방화벽을 통해 따로 접근제어를 하기 때문에
보통 서버 OS 설치 후 바로 비활성화를 합니다.
하지만 잘 알고 사용하면 보안 및 접근제어를 강화할 수 있습니다. 
추천0 비추천0

댓글목록

등록된 댓글이 없습니다.

Total 103건 1 페이지
  • 열람중 [ Server ][ Linux ] CentOS 7 SELinux 설정 및 해제하기
  • SELinux 는 Linux의 보안을 강화해 주는 보안 강화 커널이고 zero-day 공격 및 buffer overflow 등 어플리케이션 취약점으로 인한 해킹을 방지해 주는 핵심 구성요소이다. 특정 서비스가 SELinux 때문에 동작하지 않는다면 SELinux 를 끄기 보다는 해당 서비스가 SELinux 하에서 잘 동작하도록 설정을 수정하는걸 권장한다. SELinux 동작 모드 enforce, permissive, disable 세 가지 모드가 있으며 RHEL/CentOS 를 설치하...
  • 웹지기 12-13 23735 0 0 댓글 0
  • 102 [ Server ][ Linux ] cron사용법(쉘스크립트, 리눅스 파일 자동실행)
  • ## 크론설정(쉘스크립트 실행)---------- ---------- ----------------------------------------------------------------------------------------------------필 드 의 미 범 위---------- ---------- ---------------------------------------------------------------------------------------------...
  • 웹지기 09-11 21986 0 0 댓글 0
  • 101 [ Server ][ Linux ] ispconfig3 설치 및 설정
  • 우선 CentOS7 minimal 설치후 Apache로 진행된 자료 입니다. 작업시 #은 복사하지말고 복사&붙혀넣기 신공으로 따라해 보세요.....^^ 코드 붙혀넣는 작업이 더 힘드네요...아고고~ # yum -y update # yum -y install vim wget @ hosts 편집 # vim /etc/hosts 자신의 서버IP (예 : 192.168.0.100) server1.mydomain.com serve...
  • 웹지기 03-04 20946 0 0 댓글 2
  • 100 [ Server ][ Linux ] CentOS 7 virtual host 설정하기 ( 가상호스트 설정 )
  • 기본적으로 들어오는 경로에 대해 httpd.conf에 정의 되어있다. httpd.conf 백업파일 없으면 파일을 백업해둔다 cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.original httpd.conf파일을 연다. vim /etc/httpd/conf/httpd.conf httpd.conf파일의 최하단에 다음의 두 줄을 추가한다. # virtual host setting ...
  • 웹지기 12-12 18972 0 0 댓글 0
  • 99 [ Server ][ Linux ] CentOS 7 mysql MariaDB 실행 / 설정 / 방화벽
  • MariaDB 실행하기 마리아db설치는 아래 링크를 따라하세요 https://funyphp.com/archive/knowledge/109 먼저 db가 실행중인지 확인하고 실행중이 아니라면 실행을 시켜줍니다. # systemctl status mysql # systemctl start mysql 서비스에 등록이 되어있지 않으면 서비스에 등록해 준다. # systemctl enable mariadb.service 방화벽 설정 ...
  • 웹지기 12-11 18269 0 0 댓글 0
  • 98 [ Server ][ Linux ] CentOS 7 명령어 정리
  • 설치 wget [URL] : URL에 있는 파일을 다운로드 받는다. rpm rpm -Uvh [rpm] : 패키지를 설치하거나, 업그레이드 한다. rpm -qi [rpm] : 패키지가 설치 되어있는지 확인한다. rpm -e [rpm] : 패키지를 삭제 한다. yum(의존성이 있는 패키지 그룹 단위) yum -y install [패키지] : 패키지를 설치한다. yum -y erase [패키지] ...
  • 웹지기 12-11 18177 0 0 댓글 0
  • 97 [ Server ][ Linux ] FFMpeg java로 연습하기
  • FFmpeg 는 다양한 디지털 음성 스트림과 영상 스트림을 녹화, 변환할 수 있는 유틸리티 프로그램이다. 원래 리눅스용으로 개발되었으나 현재는 윈도우에서도 많이 사용하고 있다. 명령어를 직접 날려서 (윈도우라면 cmd창) 동작하는 방식이며 여러가지 프리 소프트웨어와 오픈 소스 라이브러리로 구성되어 있다. 라이브러리 중에는 libavcodec 들어있는데, 이 라이브러리는 음성/영상 코덱 라이브러리로 여러 프로젝트에서 쓰이고 있다. 또, libavformat 이라는 음성/영상 다중화, 역다...
  • 웹지기 02-28 16668 0 0 댓글 0
  • 96 [ Server ][ Linux ] centos7 FFMpeg 설치방법
  • FFmpeg는 모든 종류의 온라인 스트리밍 서비스에서 널리 사용되는 오디오 및 비디오를 기록, 변환 및 스트리밍하는 인기있는 오픈 소스 솔루션 CentOS 7 서버에 FFmpeg를 설치하는 방법을 설명 1. 시스템 업데이트 sudo yum install epel-release -y 사용금지:sudo yum update -y sudo shutdown -r now 참조 : epel = Extra Packages for Enterprise Linux→ 엔터프라이즈 리눅스를 위한 추...
  • 웹지기 02-28 16274 0 0 댓글 0
  • 95 [ Server ][ Linux ] CentOS 7 vsftp 설치 및 설정 방화벽 설정
  • vsftp 를 yum 을 이용해 설치 합니다. # yum -y update # yum install -y vsftpd systemctl 명령어로 vsftpd를 시작/중지/상태확인한다. # systemctl status vsftpd.service # systemctl start vsftpd.service # systemctl stop vsftpd.service # systemctl restart vsftpd.servi...
  • 웹지기 12-11 15442 0 0 댓글 0
  • 94 [ Server ][ Linux ] CentOS 7 계정생성 / 계정삭제, 유저계정 권한변경, 계정기본파일 …
  • 계정 생성 : useradd 계정명 계정 생성 확인 : cat /etc/passwd | grep 계정명 계정 비밀번호 생성 : passwd 계정명 기본적으로 계정을 만들면 /home/계정명으로 생성된다. 계정생성시 자동으로 폴더와 파일을 추가하려면 /etc/skel/ 폴더에 public_html 을 만들어주고 에러확인을 위한 폴더( _log )도 추가해 주자. 만들어진 public_html 폴더에 시작파일인 index.html , index.php 파일등을 만들어서 셋팅이 잘되었는지...
  • 웹지기 12-12 14067 0 0 댓글 0
  • 93 [ Server ][ Linux ] CentOS7 rewrite_mod 설정방법
  • Apache rewrite Module-작성자 : 윤일-:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />Apache 는 추가적으로 사용할 수 있는 유용한 모듈들을 제공합니다.이번강좌에서는Apache의 URL Rewrite 모듈을 사용하기 위한 컴파일,설치와 httpd.conf의 설정방법 그리고 활용방법에 대해 알아보겠습니다.Apache 다운로드 :http://www.apache.org1....
  • 웹지기 09-28 13663 0 0 댓글 2
+8
  • 92 [ Server ][ Linux ] CentOS 7 설치 및 설정하기 다섯번째 root계정 접속 막기
  • 리눅스에서 특별한 조치를 취하지 않으면 SSH포트가 열려있고, Root 계정도 활성화 되어있다. 포트스캐닝을 통해서 포트가 SSH포트가 열려있는게 확인되면 Root에 대한 무장위 대입공격을 통해 해킹을 시도한다. 오랜 해킹시도에 노출이 되면 서버보안에 큰문제가 된다. Root계정을 막기 전에 새로운 계정을 생성해 준다. useradd [ 계정이름 ] passwd [ 계정이름 ] 새 암호 : [ 암호입력 ] 새 암호 재입력 : [ 같은 암호 재입력 ] 새로운 계정을 만들었으면,...
  • 웹지기 12-10 13414 0 0 댓글 0
  • 91 [ Server ][ Linux ] CentOS 7 데몬 종류
  • NetworkManager, NetworkManagerDispatcher 네트워크 인터페이스를 자동으로 관리하기 위한 데몬 acpid ACPI(Advanced Configuration and Power Interface) 방식의 시스템 전력 관리를 위한 데몬 anacron crond와 같은 작업 스케줄러 데몬이지만 crond와는 달리 시스템이 계속 켜져있지 않다고 가정하여 하루보다 작은 단위의 스케줄을 관리 apmd APM...
  • 웹지기 12-11 13047 0 0 댓글 0
+4
  • 90 [ Server ][ Linux ] CentOS 7 ruby 설치
  • CentOS 7 에 ruby를 설치해봅시다. 일단 루비가 설치 되어있는지 검색해봅니다. 최소버젼을 이용하여 설치를 했었기 때문에 당연히 설치가 안되어있겠죠... 예상대로 설치가 되어 있지 않습니다. 그러면 루비를 설치해 보겠습니다. 중간에 이러한 질의가 뜨는군요. Is this ok [y/n]: y라고 치면 계속 진행이 됩니다. 다운로드가 계속 진행이 되고 완료가 됩니다. 설치가 완료가 되었는지 확인해보겠습니다. 설치도 완료가 되었고, 버젼도 ...
  • 웹지기 12-27 12390 0 0 댓글 0
  • 89 [ Server ][ Linux ] CentOS7 php 소스 컴파일러 설치
  • php 소스컴파일 설치1. 라이브러리 설치// 컴파일 환경설정에 추가해준 라이브러리 들을 우선적으로 설치 해야 한다.// os를 인스톨 할때 선택해 주었다면 설치할 필요가 없다.// 빠진 것이 있다면 컴파일 실행시 경고메세지와 함께 컴파일이 중지된다.--libjpeg 설치 (다운로드 하는곳)----tar xvfz jpegsrc.v7.tar.gz----cd jpegsrc-v7----./configure --enable-shared --enable-static----make----make insta...
  • 웹지기 09-27 12112 0 0 댓글 0
게시물 검색

회원로그인

접속자집계

오늘
12,042
어제
15,369
최대
33,828
전체
8,348,832

그누보드5
Copyright © funyphp.com. All rights reserved.