kickstart_자동_설치_구성

차이

문서의 선택한 두 판 사이의 차이를 보여줍니다.

차이 보기로 링크

다음 판
이전 판
kickstart_자동_설치_구성 [2025/06/10 01:05] – 만듦 koovkickstart_자동_설치_구성 [2025/07/17 06:36] (현재) – [보안취약점 적용된 kickstart 파일] koov
줄 1: 줄 1:
 ====== kickstart 자동 설치 구성 ====== ====== kickstart 자동 설치 구성 ======
 + --- //[[koovis@gmail.com|이강우]] 2025/06/10 02:18//
 +RHEL/Rocky 리눅스 설치 이후 보안취약점 적용하는것이 귀찮아서 설치할때 자동적용하도록 킥스타트파일을 만들어보았다.
  
 ===== ISO 자동설치 구성방법 ===== ===== ISO 자동설치 구성방법 =====
줄 37: 줄 39:
 <WRAP prewrap> <WRAP prewrap>
 <code kickstart> <code kickstart>
 +#########################################################
 +# LinuxDataSystem Secured kickstart file                #
 +# Version  : v1.3                                       #
 +# Target   : RHEL/Rocky 9.X                             #
 +# Date     : 2025-07-17                                 #
 +# Author   : kwlee2@linuxdata.co.kr                     #
 +#########################################################
 +
 # Keyboard layouts # Keyboard layouts
 keyboard --xlayouts='us' keyboard --xlayouts='us'
줄 65: 줄 75:
 %end %end
  
-timesource --ntp-disable 
 # System timezone # System timezone
 timezone Asia/Seoul --utc timezone Asia/Seoul --utc
 +timesource --ntp-server 0.asia.pool.ntp.org
 +timesource --ntp-server 1.asia.pool.ntp.org
 +timesource --ntp-server 2.asia.pool.ntp.org 
  
-Root password+######################################### 
 +# 계정 설정 방법 
 +# root 암호(komipo) 해시 생성 
 +# > openssl passwd -6 'Passw0rd' 
 +# 사용자 암호 해시 생성 
 +# 특수문자(#)가 포함되어 있으므로 작은따옴표(')로 감싸줍니다. 
 +# > openssl passwd -6 'Passw0rd#123' 
 +######################################### 
 +# 계정 설정
 #rootpw --iscrypted $6$BtR.Du9aLQ4TTwQw$.lyVLOQolJrZGa4I4nlk6NqZHFUTzPWc9wrn4r4JFGEUkGWj5cYsaJcIQgfuaG5H8M2VFbeC/YknXjYHdcr/p1 #rootpw --iscrypted $6$BtR.Du9aLQ4TTwQw$.lyVLOQolJrZGa4I4nlk6NqZHFUTzPWc9wrn4r4JFGEUkGWj5cYsaJcIQgfuaG5H8M2VFbeC/YknXjYHdcr/p1
-#user --groups=wheel --name=lds --password=$6$Jaa4gvCGp1yD9Zcy$oKUWX/6xr/IRXV4UZJjeBOTqyvdJTn518fDtD/eDZK.z5yWhQiqe/M5Dq7rvR4JFei0qblfSAdjRmI0U.7dlA0 --iscrypted --gecos="lds"+#user --groups=wheel --name=userid --password=$6$Jaa4gvCGp1yD9Zcy$oKUWX/6xr/IRXV4UZJjeBOTqyvdJTn518fDtD/eDZK.z5yWhQiqe/M5Dq7rvR4JFei0qblfSAdjRmI0U.7dlA0 --iscrypted --gecos="username"
  
-%post --log=/root/kickstart-post.log+######################################## 
 +# 방화벽 정책 적용 
 +# 비활성화 하는 경우 
 +firewall --disabled 
 + 
 +# 활성화 하는 경우 
 +#firewall --enabled --service=ntp,nfs,http,https --port=2181:tcp,7000:tcp,7001:tcp,8020:tcp,8081:tcp,8082:tcp,8083:tcp,8091:tcp,8369:tcp,8888:tcp,20808:tcp,20809:tcp,20987:tcp,22909:tcp,26330:tcp,28081:tcp,28082:tcp
  
 ######################################## ########################################
-# Disable and stop firewalld +보안 취약점 적용 내역 
-systemctl stop firewalld +######################################## 
-systemctl disable firewalld +# 01. Disable and stop firewalld 
-systemctl mask firewalld +# 02. 패스워드 복잡성 설정 U-2 
-echo "Firewalld service has been stopped and disabled."+# 03. 계정 잠금 임계값 설정 U-3 
 +# 04. root 계정 su 제한 U-45 
 +# 05. 패스워드 최소 길이 설정 (login.defs) U-46 
 +# 06. 패스워드 최대 사용기간 설정 (login.defs) U-47 
 +# 07. 패스워드 최소 사용기간 설정 (login.defs) U-48 
 +# 08. Session Timeout 설정 U-54 
 +# 09. /etc/hosts 파일 소유자 및 권한 설정 U-9 
 +# 10. /etc/rsyslog.conf 파일 소유자 및 권한 설정 U-11 
 +# 11. SUID, SGID 파일 점검 (at 명령어 SUID 제거는 선택적) U-13 
 +# 12. UMASK 설정 관리 (RHEL 9 기본 0022, 변경 시 주석 해제) U-56 
 +# 13. cron 파일 소유자 및 권한 설정 U-22 
 +# 14. $HOME/.rhosts, hosts.equiv 사용 금지 U-17 
 +# 15. 접속 IP 및 포트 제한 (firewalld) U-18 
 +# 16Postfix 보안 설정 (Postfix 설치 시) U-31 
 +# 17. ssh 원격접속 보안 강화 
 +# - [SSH 포트 번호 변경] 
 +# - [Root 계정 원격 접속 제한] U-1 
 +# - [.rhosts 및 hosts.equiv 사용 금지] U-17 
 +# - [SSH 원격접속 보안 강화 (CIS Benchmark 권장 사항 등)] U-60 
 +# - [로그온 시 경고 메시지 제공] U-68 
 +# 18. at 파일 소유자 및 권한 설정 U-65 
 +# 19. 로그온 시 경고 메시지 제공 U-68 
 +# 20. 최신 보안패치 적용 U-42 
 +# 21. 시스템 로깅 설정 (rsyslog, auditd) 
 +# 22. 터미널 명령어 로깅 
 +# 23. ulimit 설정 
 +########################################
  
 +%post --log=/root/kickstart-post.log
 echo "Starting RHEL 9 Security Hardening Post-Install Script" echo "Starting RHEL 9 Security Hardening Post-Install Script"
- +######################################## 
---- 2.1정 및 접근 통제 ---+02패스워드 복잡성 설
 echo "Applying Account and Access Control settings..." echo "Applying Account and Access Control settings..."
  
-# 2.1.2. 패스워드 복잡성 설정 
 # 기본 주석 처리된 값을 변경하거나, 라인이 없으면 추가합니다. # 기본 주석 처리된 값을 변경하거나, 라인이 없으면 추가합니다.
 # 예시 값이며, 실제 보안 정책에 맞게 조정하십시오. # 예시 값이며, 실제 보안 정책에 맞게 조정하십시오.
줄 120: 줄 172:
 fi fi
  
-2.1.3. 계정 잠금 임계값 설정+######################################## 
 +03. 계정 잠금 임계값 설정
 # 시스템 환경에 맞는 프로파일 선택 (예: sssd) # 시스템 환경에 맞는 프로파일 선택 (예: sssd)
 authselect select sssd --force authselect select sssd --force
줄 160: 줄 213:
 fi fi
  
- +######################################## 
-2.1.6. root 계정 su 제한+04. root 계정 su 제한
 # /etc/pam.d/su 파일에서 pam_wheel.so 활성화 # /etc/pam.d/su 파일에서 pam_wheel.so 활성화
 # 해당 라인이 이미 존재하고 주석 처리되어 있다면 주석 해제 # 해당 라인이 이미 존재하고 주석 처리되어 있다면 주석 해제
줄 175: 줄 228:
 chmod 4750 /usr/bin/su chmod 4750 /usr/bin/su
  
- +######################################## 
-2.1.7. 패스워드 최소 길이 설정 (login.defs)+05. 패스워드 최소 길이 설정 (login.defs)
 # /etc/login.defs 파일의 PASS_MIN_LEN 값을 9로 설정 (pwquality.conf의 minlen과 일치 권장) # /etc/login.defs 파일의 PASS_MIN_LEN 값을 9로 설정 (pwquality.conf의 minlen과 일치 권장)
 if grep -q "^PASS_MIN_LEN" /etc/login.defs; then if grep -q "^PASS_MIN_LEN" /etc/login.defs; then
줄 184: 줄 237:
 fi fi
  
-2.1.8. 패스워드 최대 사용기간 설정 (login.defs)+######################################## 
 +# 06. 패스워드 최대 사용기간 설정 (login.defs)
 # /etc/login.defs 파일의 PASS_MAX_DAYS 값을 90으로 설정 # /etc/login.defs 파일의 PASS_MAX_DAYS 값을 90으로 설정
 if grep -q "^PASS_MAX_DAYS" /etc/login.defs; then if grep -q "^PASS_MAX_DAYS" /etc/login.defs; then
줄 197: 줄 251:
 # done # done
  
-2.1.9. 패스워드 최소 사용기간 설정 (login.defs)+######################################## 
 +# 07. 패스워드 최소 사용기간 설정 (login.defs)
 # /etc/login.defs 파일의 PASS_MIN_DAYS 값을 1로 설정 # /etc/login.defs 파일의 PASS_MIN_DAYS 값을 1로 설정
 if grep -q "^PASS_MIN_DAYS" /etc/login.defs; then if grep -q "^PASS_MIN_DAYS" /etc/login.defs; then
줄 210: 줄 265:
 # done # done
  
-2.1.15. Session Timeout 설정+######################################## 
 +# 08. Session Timeout 설정
 # /etc/profile.d/custom_env.sh 파일 생성 # /etc/profile.d/custom_env.sh 파일 생성
 cat <<'EOF' > /etc/profile.d/custom_env.sh cat <<'EOF' > /etc/profile.d/custom_env.sh
줄 236: 줄 292:
 chmod 644 /etc/profile.d/custom_env.sh chmod 644 /etc/profile.d/custom_env.sh
  
---- 2.2. 파일시스템, 디렉토리 및 권한 ---+######################################## 
 +# 09/etc/hosts 파일 소유자 및 권한 설정
 echo "Applying Filesystem, Directory, and Permission settings..." echo "Applying Filesystem, Directory, and Permission settings..."
  
-# 2.2.5. /etc/hosts 파일 소유자 및 권한 설정 
 #chown root:root /etc/hosts #chown root:root /etc/hosts
 #chmod 644 /etc/hosts #chmod 644 /etc/hosts
  
-2.2.6. /etc/rsyslog.conf 파일 소유자 및 권한 설정+######################################## 
 +# 10. /etc/rsyslog.conf 파일 소유자 및 권한 설정
 chown root:root /etc/rsyslog.conf chown root:root /etc/rsyslog.conf
 chmod 640 /etc/rsyslog.conf chmod 640 /etc/rsyslog.conf
줄 249: 줄 306:
 # find /etc/rsyslog.d/ -type f -exec chown root:root {} \; # find /etc/rsyslog.d/ -type f -exec chown root:root {} \;
  
-2.2.8. SUID, SGID 파일 점검 (at 명령어 SUID 제거는 선택적)+######################################## 
 +# 11. SUID, SGID 파일 점검 (at 명령어 SUID 제거는 선택적)
 # /usr/bin/at 의 SUID 제거 (atd 서비스를 사용하지 않거나, 사용을 엄격히 제한할 경우에만 고려) # /usr/bin/at 의 SUID 제거 (atd 서비스를 사용하지 않거나, 사용을 엄격히 제한할 경우에만 고려)
 # if [ -f /usr/bin/at ]; then # if [ -f /usr/bin/at ]; then
줄 263: 줄 321:
 # find / -xdev \( -perm -4000 -o -perm -2000 \) -type f -ls >> /root/suid_sgid_check.log 2>/dev/null # find / -xdev \( -perm -4000 -o -perm -2000 \) -type f -ls >> /root/suid_sgid_check.log 2>/dev/null
  
-2.2.12. UMASK 설정 관리 (RHEL 9 기본 0022, 변경 시 주석 해제)+######################################## 
 +12. UMASK 설정 관리 (RHEL 9 기본 0022, 변경 시 주석 해제)
 # RHEL 9 기본 umask는 0022이므로, 0022를 목표로 한다면 별도 조치 불필요. # RHEL 9 기본 umask는 0022이므로, 0022를 목표로 한다면 별도 조치 불필요.
 # 만약 더 엄격한 umask 027 로 변경하고자 할 경우: # 만약 더 엄격한 umask 027 로 변경하고자 할 경우:
줄 276: 줄 335:
 # fi # fi
  
-2.2.16. cron 파일 소유자 및 권한 설정+######################################## 
 +# 13. cron 파일 소유자 및 권한 설정
 # 주요 cron 파일 및 디렉토리 권한 설정 # 주요 cron 파일 및 디렉토리 권한 설정
 chown root:root /etc/crontab chown root:root /etc/crontab
줄 313: 줄 373:
 chmod 4750 /usr/bin/crontab chmod 4750 /usr/bin/crontab
  
---- 2.3서비스 및 네트워크 ---+######################################## 
 +# 14$HOME/.rhosts, hosts.equiv 사용 금지 
 echo "Applying Service and Network settings..." echo "Applying Service and Network settings..."
  
-# 2.3.2. $HOME/.rhosts, hosts.equiv 사용 금지 
 # 시스템 전체에서.rhosts 파일 검색 및 삭제 # 시스템 전체에서.rhosts 파일 검색 및 삭제
 find /home -name .rhosts -type f -delete find /home -name .rhosts -type f -delete
줄 324: 줄 385:
 rm -f /etc/hosts.equiv rm -f /etc/hosts.equiv
  
-2.3.3. 접속 IP 및 포트 제한 (firewalld) - Kickstart 명령어 섹션에서 기본 설정 권장+######################################## 
 +# 15. 접속 IP 및 포트 제한 (firewalld) - Kickstart 명령어 섹션에서 기본 설정 권장
 # Kickstart 명령어 섹션 (예시) # Kickstart 명령어 섹션 (예시)
 # firewall --enabled --service=ssh # firewall --enabled --service=ssh
줄 342: 줄 404:
 # firewall-cmd --reload # 설치 마지막에 한 번만 실행하는 것이 좋음 # firewall-cmd --reload # 설치 마지막에 한 번만 실행하는 것이 좋음
  
-2.3.15. Postfix 보안 설정 (Postfix 설치 시)+######################################## 
 +# 16. Postfix 보안 설정 (Postfix 설치 시)
 # Sendmail 패키지는 설치하지 않음 (-sendmail) # Sendmail 패키지는 설치하지 않음 (-sendmail)
 # Postfix 설치 시 (예: dnf install postfix) 보안 설정 적용 # Postfix 설치 시 (예: dnf install postfix) 보안 설정 적용
줄 352: 줄 415:
 fi fi
  
-2.3.18. ssh 원격접속 보안 강화+######################################## 
 +# 17. ssh 원격접속 보안 강화
 # ############################################################################## # ##############################################################################
 # SSH 보안 설정 통합 (수정된 부분) # SSH 보안 설정 통합 (수정된 부분)
 # ############################################################################## # ##############################################################################
 echo "Applying consolidated SSH security settings..." echo "Applying consolidated SSH security settings..."
 +
 +########################################
 +# [SSH 포트 번호 변경]
 +#echo "Changing SSH port to 2222"
 +#sed -i 's/^#*Port 22/Port 2222/' /etc/ssh/sshd_config
  
 # /etc/ssh/sshd_config.d/ 디렉토리에 단일 설정 파일 생성 # /etc/ssh/sshd_config.d/ 디렉토리에 단일 설정 파일 생성
줄 368: 줄 437:
 cat <<EOF > "$CUSTOM_SSH_CONFIG_FILE" cat <<EOF > "$CUSTOM_SSH_CONFIG_FILE"
 # This file was generated by Kickstart and contains consolidated security settings. # This file was generated by Kickstart and contains consolidated security settings.
- 
 # [Root 계정 원격 접속 제한] # [Root 계정 원격 접속 제한]
 PermitRootLogin no PermitRootLogin no
줄 395: 줄 463:
  
 EOF EOF
 +########################################
  
 # 파일 권한 설정 # 파일 권한 설정
줄 404: 줄 473:
 # ############################################################################## # ##############################################################################
  
- +######################################## 
-2.3.20. at 파일 소유자 및 권한 설정+18. at 파일 소유자 및 권한 설정
 echo "Disabling atd service..." echo "Disabling atd service..."
 # systemctl을 사용하여 atd 서비스를 비활성화 및 중지합니다. # systemctl을 사용하여 atd 서비스를 비활성화 및 중지합니다.
줄 432: 줄 501:
 fi fi
  
-2.3.22. 로그온 시 경고 메시지 제공+######################################## 
 +# 19. 로그온 시 경고 메시지 제공
 BANNER_TEXT=" BANNER_TEXT="
 ########################################################################## ##########################################################################
 # WARNING: This system is for the use of authorized users only.          # # WARNING: This system is for the use of authorized users only.          #
 # Individuals using this computer system without authority, or in excess # # Individuals using this computer system without authority, or in excess #
-# of their authority, are subject to having all oftheir activities on    #+# of their authority, are subject to having all of their activities on   #
 # this system monitored and recorded by system personnel.                # # this system monitored and recorded by system personnel.                #
 #                                                                        # #                                                                        #
줄 455: 줄 525:
 echo "$BANNER_TEXT" > /etc/issue.net echo "$BANNER_TEXT" > /etc/issue.net
  
---- 2.4. 로그 및 감사, 패치 ---+######################################## 
 +# 20최신 보안패치 적용
 echo "Applying Logging, Auditing, and Patching settings..." echo "Applying Logging, Auditing, and Patching settings..."
  
-# 2.4.1. 최신 보안패치 적용 
 #echo "Applying latest security patches..." #echo "Applying latest security patches..."
 #dnf update -y #dnf update -y
줄 466: 줄 536:
 # systemctl enable --now dnf-automatic.timer # systemctl enable --now dnf-automatic.timer
  
-2.4.3. 시스템 로깅 설정 (rsyslog, auditd) - 기본 예+######################################## 
 +# 21. 시스템 로깅 설정 (rsyslog, auditd) 
 +# echo "내용" >> 파일경로 형식은 파일의 맨 마지막에 내용을 추가합니다. 
 +echo "*.alert                                                 /dev/console" >> /etc/rsyslog.conf 
 + 
 +# audit 로그 설정 (필요시 주석 해제)
 # echo "authpriv.* /var/log/auth.log" > /etc/rsyslog.d/custom-auth.conf # echo "authpriv.* /var/log/auth.log" > /etc/rsyslog.d/custom-auth.conf
 # dnf install -y audit; systemctl enable --now auditd # dnf install -y audit; systemctl enable --now auditd
줄 472: 줄 547:
 # augenrules --load # augenrules --load
  
 +########################################
 +# 22. 터미널 명령어 로깅
 +echo "Starting command logging configuration..."
 +
 +# 1. /etc/profile.d/ 에 명령어 로깅 스크립트 생성
 +# 'EOF'에 작은 따옴표를 사용하여 변수($USER, $PWD 등)가 지금 확장되지 않고
 +# 사용자가 로그인할 때 동적으로 확장되도록 합니다.
 +cat <<'EOF' > /etc/profile.d/command-logging.sh
 +#!/bin/bash
 +# Script to log user commands to syslog
 +
 +# history -a: 현재 세션의 히스토리를 즉시 파일에 쓰도록 함
 +# logger: history의 마지막 명령어를 가져와 syslog로 전송
 +# -p local6.info: local6 facility, info 레벨로 로그 전송
 +# -t bash-commands: 로그에 'bash-commands' 태그 추가
 +export PROMPT_COMMAND='history -a; logger -p local6.info -t bash-commands "USER=$USER IP=$(who -m | awk "{print \$5}" | tr -d "()") PWD=$PWD CMD=$(history 1 | sed "s/^[ ]*[0-9]\+[ ]*//")"'
 +EOF
 +
 +# 스크립트에 실행 권한 부여
 +chmod +x /etc/profile.d/command-logging.sh
 +echo ">>> Created /etc/profile.d/command-logging.sh"
 +
 +# 2. rsyslog 설정 파일 생성
 +# local6 facility로 들어오는 로그를 /var/log/command.log 파일에 기록하도록 설정
 +cat <<EOF > /etc/rsyslog.d/command-logging.conf
 +# Rule for command logging
 +local6.* /var/log/command.log
 +EOF
 +echo ">>> Created /etc/rsyslog.d/command-logging.conf"
 +
 +# 3. logrotate 설정 파일 생성
 +# /var/log/command.log 파일을 자동으로 관리(로테이트)하도록 설정
 +cat <<EOF > /etc/logrotate.d/command-log
 +/var/log/command.log {
 +    missingok
 +    notifempty
 +    create 0600 root root
 +    postrotate
 +        /bin/systemctl kill -s HUP rsyslogd.service >/dev/null 2>&1 || true
 +    endscript
 +}
 +EOF
 +echo ">>> Created /etc/logrotate.d/command-log"
 +
 +echo ">>> Command logging configuration finished."
 +
 +########################################
 +# 23. ulimit 설정
 +echo "Starting ulimit configuration..."
 +# /etc/security/limits.d/ 디렉터리에 nofile 설정을 위한 파일을 생성합니다.
 +# 파일 이름은 .conf로 끝나야 하며, 일반적으로 우선순위를 위해 숫자로 시작합니다 (예: 99-).
 +
 +cat <<EOF > /etc/security/limits.d/99-custom-nofile.conf
 +# Set custom nofile limits for all users
 +* soft   nofile   65536
 +* hard   nofile   65536
 +EOF
 +
 +# systemd의 기본 LimitNOFILE 값을 설정합니다.
 +# /etc/systemd/system.conf 파일에서 DefaultLimitNOFILE 주석을 제거하고 값을 설정합니다.
 +# /etc/systemd/user.conf 파일에서 DefaultLimitNOFILE 주석을 제거하고 값을 설정합니다.
 +# -i 옵션은 파일을 직접 수정합니다.
 +sed -i 's/^#DefaultLimitNOFILE=.*/DefaultLimitNOFILE=65536/' /etc/systemd/system.conf
 +sed -i 's/^#DefaultLimitNOFILE=.*/DefaultLimitNOFILE=65536/' /etc/systemd/user.conf
 +# DefaultLimitNPROC 값도 동일하게 변경할 수 있습니다.
 +# sed -i 's/^#DefaultLimitNPROC=.*/DefaultLimitNPROC=65536/' /etc/systemd/system.conf
 +# sed -i 's/^#DefaultLimitNPROC=.*/DefaultLimitNPROC=65536/' /etc/systemd/user.conf
 +echo ">>> ulimit configuration finished."
 +
 +
 +################################
 # --- 서비스 재시작 (설치 마지막에 한 번만 수행 권장) --- # --- 서비스 재시작 (설치 마지막에 한 번만 수행 권장) ---
 echo "Restarting services..." echo "Restarting services..."
  • kickstart_자동_설치_구성.1749517503.txt.gz
  • 마지막으로 수정됨: 2025/06/10 01:05
  • 저자 koov