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

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

linux

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

페이지 정보

작성자 웹지기 댓글 0건 조회 23,875회 작성일 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건 6 페이지
  • 28 [ Server ][ Linux ] 리눅스 텔넷 기본 명령어
  • 퍼미션(권한)이란?wxrwxrwxr은 파일 읽기(4), w는 파일 쓰기(2), x는 파일 실행(1)755파일소유자는 그것을 읽고 쓰고 실행시킬 수 있지만, 제3자는 읽고 실행만 시킬 수 있다.777제3자도 쓰기 권한이 주어진다.*.html *.cgi, *.pl *.txt등의 파일은 업로드시 반드시 ascii로하고나머지 그림(*.gif *.jpg)이나 자바 애플릿(*.class), 실행파일(*.exe *.zip *.rar)등은 binary mode로 업로드 할 것.리눅스 기본명령어이들 앨리어스는 [...
  • 웹지기 10-01 10604 0 0 댓글 0
  • 27 [ Server ][ Linux ][ Software ] ssh 사용법 및 기본 명령어
  • 기본적인 명령어..-> login유닉스 시스템은 기본적으로 multi-user개념에서 시작하였기 때문에 시스템을 이용하기 위해서는 반드시 로그인을 하셔야 합니다.로그인은 PC 통신에서도 많이 사용되어져 왔기 때문에 그 개념 설정에 그다지 어려움이 없을 것입니다.흔히 말하는 ID를 입력하는 과정입니다. 유닉스 시스템에서는 영문자의 대소문자 구별이 엄격합니다.이점을 주의 하시길 바랍니다. (login 의 반대는 logout 또는 exit 또는 ctrl-D)-> passwd...
  • 웹지기 10-01 10245 0 0 댓글 0
  • 25 [ Server ][ Linux ] CentOS 7 설치 및 설정하기 사용자 생성시 디렉토리(public_h…
  • 계정생성시 디렉토리와 기본 파일을 자동으로 추가하게 설정. 기본폴더 즉 /etc/skel 디렉토리 하단에 public_html을 만들고 public_html하단에 index.html과 같은 기본 파일을 만들어서 확인할 수 있게 해준다 /etc/skel/public_html/index.html(php) 와 같이 만들어주면 계정생성시 자동으로 디렉토리와 파일이 추가된다. [이 게시물은 웹지기님에 의해 2019-03-15 15:33:17 knowledge에서 이동 됨]
  • 웹지기 12-10 10484 0 0 댓글 0
+8
  • 24 [ Server ][ Linux ] CentOS 7 설치 및 설정하기 다섯번째 root계정 접속 막기
  • 리눅스에서 특별한 조치를 취하지 않으면 SSH포트가 열려있고, Root 계정도 활성화 되어있다. 포트스캐닝을 통해서 포트가 SSH포트가 열려있는게 확인되면 Root에 대한 무장위 대입공격을 통해 해킹을 시도한다. 오랜 해킹시도에 노출이 되면 서버보안에 큰문제가 된다. Root계정을 막기 전에 새로운 계정을 생성해 준다. useradd [ 계정이름 ] passwd [ 계정이름 ] 새 암호 : [ 암호입력 ] 새 암호 재입력 : [ 같은 암호 재입력 ] 새로운 계정을 만들었으면,...
  • 웹지기 12-10 13546 0 0 댓글 0
+1
  • 23 [ Server ][ Linux ] CentOS 7 설치 및 설정하기 네번째 서버에 apm설치(httpd, …
  • APM 설치를 진행한다. 간편한 작업을 위해https://sir.kr/so_server/1945 apm auto installer을 다운받습니다. 압축을 푸시면 APM 사용 설명서.txt가 포함되어 있습니다. 이부분을 읽고 따라하면 됩니다.(간단함) 저는 root로 접속해서 APMinstaller.sh를 퍼미션 변경 후 실행했습니다. 설치가 끝나고 php버젼을 확인해 보았습니다. 오류없이 설치가 잘 마무리가 되고 Complete! 라는 내용이 떳네요. php 버젼에 7.2....
  • 웹지기 12-10 9444 0 0 댓글 0
+8
  • 21 [ Server ][ Linux ] CentOS 7 설치 및 설정하기 두번째 CentOS7 설치
  • 만들어진 USB로 부팅을 한다. 부팅 USB가 없다면https://funyphp.com/archive/knowledge/106 부분을 따라서 한다. Install CentOS7 을 선택한다. 언어설정에서 한국어를 선택한다. 먼저 네트워크 및 호스트명으로 이동해서 네트워크를 설정한다. 다음 설치대상에서 파티션을 설정한다. 소프트웨어 선택은 최소설치다. 이더넷을 켜고 설정을 통해서 ip를 자동 또는 수동 조정이 가능하다. 본인의 ip를 잘 기억해서 기본 설치 이외...
  • 웹지기 12-10 9771 0 0 댓글 0
+6
  • 20 [ Server ][ Linux ] CentOS 7 설치 및 설정하기 첫번째 부팅 USB만들기
  • CentOS 7 설치를 위해rufus-3.4p 와 CentOS7 다운로드 사이트로 이동해서 최소설치 버젼(Minimal ISO)를 다운을 받는다. 다운이 완료되었으면 부팅 USB를 만들어보자 rufus-3.4를 실행시키면 다음의 화면과 함께 부팅 USB를 만드는 조건이 시작된다. 다음과 같이 진행을 하면 된다.(USB라서 다소 시간이 걸릴 수 있습니다.) 그림에서 선택부분을 눌러서 CentOS7-x86_64-Minimal-1810.iso 파일을 선택해 주고, 볼륨레이블 ...
  • 웹지기 12-10 10758 0 0 댓글 0
  • 19 [ Server ][ Linux ][ ubuntu ] sass install, 우분투에 sass 설치하기
  • 일단 우분투서버에 ruby가 설치되어 있어다는 조건하에. :sass -v 있다면 버젼이 나오고 없다면 설치하라는 명령이 뜰것이다. 설치가 되어있지 않다면 :apt-get install ruby-sass 중간에 y/n 질문을 하면 y를 눌러주면 된다. 설치가 완료 되었으면. 버젼을 확인하자 :sass -v :Sass 3.4.21 (Selective Steve) 버젼이 나오면 성공한것이다. [이 게시물은 웹지기님에 의해 2019-03-15 15:33:17 knowledge에서 ...
  • 웹지기 12-05 8812 0 0 댓글 0
  • 18 [ Server ][ Linux ] ubuntu ruby install, git install, 우분투에서…
  • 룻트폴더로 이동 :cd ~ :ruby --version 버젼이 나오지 않으면 설치가 되어있지 않는 것이다. :sudo apt-get update :sudo에 대한 비밀번호 입력 업데이트가 진행된다. apt-get 명령을 통해 rbenv 와 ruby 를 설치한다. :apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxm...
  • 웹지기 12-05 9773 0 0 댓글 0
  • 열람중 [ Server ][ Linux ] CentOS 7 SELinux 설정 및 해제하기
  • SELinux 는 Linux의 보안을 강화해 주는 보안 강화 커널이고 zero-day 공격 및 buffer overflow 등 어플리케이션 취약점으로 인한 해킹을 방지해 주는 핵심 구성요소이다. 특정 서비스가 SELinux 때문에 동작하지 않는다면 SELinux 를 끄기 보다는 해당 서비스가 SELinux 하에서 잘 동작하도록 설정을 수정하는걸 권장한다. SELinux 동작 모드 enforce, permissive, disable 세 가지 모드가 있으며 RHEL/CentOS 를 설치하...
  • 웹지기 12-13 23876 0 0 댓글 0
  • 16 [ 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 19077 0 0 댓글 0
  • 15 [ Server ][ Linux ] CentOS 7 계정생성 / 계정삭제, 유저계정 권한변경, 계정기본파일 …
  • 계정 생성 : useradd 계정명 계정 생성 확인 : cat /etc/passwd | grep 계정명 계정 비밀번호 생성 : passwd 계정명 기본적으로 계정을 만들면 /home/계정명으로 생성된다. 계정생성시 자동으로 폴더와 파일을 추가하려면 /etc/skel/ 폴더에 public_html 을 만들어주고 에러확인을 위한 폴더( _log )도 추가해 주자. 만들어진 public_html 폴더에 시작파일인 index.html , index.php 파일등을 만들어서 셋팅이 잘되었는지...
  • 웹지기 12-12 14171 0 0 댓글 0
  • 14 [ Server ][ Linux ] CentOS 7 apm auto install 설치 이후 phpMyAdm…
  • 일반적으로 인터넷에 올라와있는 방법으로 했더니 오류가 발생한다. Error: Package: php-recode-5.4.45-16.el7.remi.x86_64 (remi) Requires: php-common(x86-64) = 5.4.45-16.el7.remi Installed: php-common-7.2.13-2.el7.remi.x86_64 (@remi-php72) php-common(x86-64) = 7.2.13-2.el7.remi...
  • 웹지기 12-11 10318 0 0 댓글 0
게시물 검색

회원로그인

접속자집계

오늘
2,255
어제
7,139
최대
33,828
전체
8,415,950

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