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

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

linux

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

페이지 정보

작성자 웹지기 댓글 0건 조회 23,867회 작성일 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건 5 페이지
  • 43 [ Server ][ Linux ] centos7 git 버젼업데이트
  • # make configure # ./configure --prefix=/usr # make all doc info @make all doc info 설치시 오류가 발생 @Can't locate ExtUtils/MakeMaker.pm 해결방법 # yum install perl-CPAN # sudo make install install-doc install-html install-info # git --...
  • 웹지기 04-01 8096 0 0 댓글 0
+1
  • 42 [ Server ][ Linux ] centos7 java ( jdk )설치 및 설정
  • @wget을 통해서 설치하므로 wget 설치 # yum install -y wget @다운로드 페이지로 이동해서 다운받을 버젼을 확인한다. https://www.oracle.com/technetwork/java/javase/downloads/index.html @설치된 리눅스의 비트수를 확인하고 거기에 맞는 버젼을 다운받아야 한다 # getconf LONG_BIT @다운로드를 눌러 페이지를 이동한후 승인을 눌러준 후 환...
  • 웹지기 03-18 10117 0 0 댓글 0
  • 41 [ Server ][ Linux ] CentOS7 cron 사용하기 / 파일 자동 실행 설정
  • 1. cron 설정[code][root@linux]# crontab -l//현재 cron 확인[root@linux]# crontab -e//cron 편집 - vi 와 사용법 같음(예)[root@SRV182 ~]# crontab -l30 04 10 * * /root/cron/account_month.php//매월 10일 04시 30분에 /root/cron/account_month.php를 실행하라[/code](필드 설정)필드번호의미첫번째 필드“분(minute)”을 의미. 0,1,2,3,,,,59분까...
  • 웹지기 09-27 11610 0 0 댓글 0
  • 40 [ 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 13755 0 0 댓글 2
+1
  • 39 [ Server ][ Linux ] CentOS7 php_screw-1.5 설치 (php 소스 암호화)
  • * 설명php_screw 모듈을 설치하면 php 소스를 암호화 할 수 있다.php 가 설치되어 있는 상태에서 모듈만 추가한다.*소스 다운로드wgethttp://sourceforge.net/projects/php-screw/files/php-screw/1.5/php_screw-1.5.tar.gz*설치[root@ php_screw-1.5]# phpizeConfiguring for:PHP Api Version: 20041225Zend Module Api No: 20060613Zend Extension ...
  • 웹지기 09-27 9020 0 0 댓글 0
  • 38 [ 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 12179 0 0 댓글 0
  • 37 [ Server ][ Linux ][ htaccess ] 아이피 차단 관련 설정
  • * 국내아이피를 제외한 나머지 국가에 대해 아이피 차단시 첨부화일을 참고!* 특정 아이피를 차단할경우.htaccess 파일을 편집(만약 123.45.123.45 를 막는다고 할때) :namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />SetEnvIfNoCase remote_addr 123.45.123.45 go_outOrder allow,denyAllow from allDeny from env...
  • 웹지기 10-01 8671 0 0 댓글 0
  • 35 [ Server ][ Linux ] cron사용법(쉘스크립트, 리눅스 파일 자동실행)
  • ## 크론설정(쉘스크립트 실행)---------- ---------- ----------------------------------------------------------------------------------------------------필 드 의 미 범 위---------- ---------- ---------------------------------------------------------------------------------------------...
  • 웹지기 09-11 22070 0 0 댓글 0
  • 34 [ Server ][ Linux ] 계정 용량 확인 / 관리
  • [code]<?php$du=`du -sk`;$save=100; //할당받은 계정용량, 단위 MBytes$du=$du/1000;$result1=$save-$du;$result2=$du;echo "<font size='2' color='#0078FF'>전체 용량 :<font size='2' color='#ff6666'> 100MB</font><br>";ec...
  • 웹지기 09-30 8433 0 0 댓글 0
  • 33 [ Server ][ Linux ] HTTP 1.1 분류 코드표(에러 코드표)
  • HTTP 에러 코드표 (from. 네이버 오픈백과)100 ::: Continue101 ::: Switching Protocols200 ::: OK, 에러없이 전송 성공202 ::: Accepted, 서버가 클라이언트의 명령을 받음.203 ::: Non-authoritavive Information, 서버가 클라이언트 요구중 일부만 정송204 ::: Non Content, 클라이언트 요구를 처리했으나 전송할 데이터가 없음.205 ::: Reset Content206 ::: Partial Conten...
  • 웹지기 09-30 9073 0 0 댓글 0
  • 32 [ Server ][ Linux ] 리눅스 호스팅 서버 관리
  • ■리눅스 호스팅서버 관리************************************************************ 리눅스 호스팅서버 관리************************************************************ 호스팅서비스에 필요한 것들- 리눅스 운영체제- 아파치 웹서버- MySQL 데이터베이스- PHP, Perl 등과 같은 웹프로그래밍언어- 메일서비스 지원을 위한 Sendmail, Qmail, POP, IMAP- Webalizer와 access...
  • 웹지기 09-30 8314 0 0 댓글 0
  • 31 [ Server ][ Linux ] MySQL + Apache + PHP + Zend Optimizer 설치
  • ########################################################### 문서명 : MySQL + Apache + PHP + Zend Optimizer 설치 ## 작성자 : 임희 ## 작성일 : 2003 년 12 월 23 일 (화) 13:00 ## 수정일 : 2004 년 03 월 05 일 (금) 17:00 (수정) ## 수정일 : 2005 년 05 월 21 일 (토) 10:00 (수정) ## 작성서버: KERNEL - 2.4.23 / CPU : P-III 1G /...
  • 웹지기 09-28 10759 0 0 댓글 0
  • 30 [ Server ][ Linux ] 리눅스 파일만들기, 파일옮기기,폴더옮기기, 복사하기, 화면 지우기
  • 리눅스 파일만들기, 파일옮기기, 복사하기, 화면 지우기mv - 이름변경 및 이동을 담당mv 원본파일 대상파일예를들어 test.txt라는 파일이 있다고 치고 나는 /home 디렉토리로 옮기고 싶다면mv test.txt /home로 옮길수 있다.만약 mv test.txt test1.txt라고 한다면 기존의 파일은 사라지고 이름이 변경되게 된다.cp - 파일이나 디렉토리를 다른파일 또는 다른 디렉토리로 복사를 수행한다.cp 원본파일 대상파일cp test.txt /home 이런식으로 사용한다면 test....
  • 웹지기 09-28 10531 0 0 댓글 0
  • 29 [ Server ][ Linux ] httpd.conf 서버 디렉토리 보이게, 안보이게 설정
  • httpd.conf 파일에서 아파치 서버 디렉토리의 폴더및 파일을 보여주거나, 파일 및 폴더를 보여주지않고 오류를 출력할 때 설정 방법. <Directory "D:/AutoSet9/public_html"> #index파일이 없을 때 디렉토리를 감추고 에러를 출력 Options FollowSymLinks #index파일이 없을 때 디렉토리를 보여줌 Options Indexes FollowSymLinks </Di...
  • 웹지기 11-26 8635 0 0 댓글 0
게시물 검색

회원로그인

접속자집계

오늘
5,084
어제
9,384
최대
33,828
전체
8,411,640

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