리눅스 초기 보안 설정

EnoSoup·2021년 7월 23일
0

Linux

목록 보기
2/15
post-thumbnail

설정 방법

sshd 접속 횟수 설정 및 root 접속 금지/ip 차단 방법

# sshd 접속횟수 설정
$ sudo vi /etc/ssh/sshd_config

# Authentication:

PermitRootLogin no  <<-- root 접속금지
MaxAuthTries 6      <<-- 6회 까지만 허용 그뒤로 차단

# ssh 접속 허용 할 ip 추가
$ sudo vi /etc/hosts.allow
#
# hosts.allow   This file contains access rules which are used to
#               allow or deny connections to network services that
#               either use the tcp_wrappers library or that have been
#               started through a tcp_wrappers-enabled xinetd.
#
#               See 'man 5 hosts_options' and 'man 5 hosts_access'
#               for information on rule syntax.
#               See 'man tcpd' for information on tcp_wrappers
#
sshd: 000.000.000.000  <<-- IP만 허용 시 
sshd: 172.16.          <<-- 대역 허용 시

# ssh 접속 차단설정
$ sudo vi /etc/hosts.deny
#
# hosts.deny    This file contains access rules which are used to
#               deny connections to network services that either use
#               the tcp_wrappers library or that have been
#               started through a tcp_wrappers-enabled xinetd.
#
#               The rules in this file can also be set up in
#               /etc/hosts.allow with a 'deny' option instead.
#
#               See 'man 5 hosts_options' and 'man 5 hosts_access'
#               for information on rule syntax.
#               See 'man tcpd' for information on tcp_wrappers
#
sshd: ALL     <<-- hosts.allow 에 허용 된 IP 외 전체차단

특정 서비스 포트 차단

  • SSHBruteForce, ProtScan 시 22, 111, 25, 21 포트 등으로 스캔 및 무차별대입
    공격을 시행함. 이와 관련 미사용 서비스포트는 차단하는 것이 좋음.
$ sudo systemctl stop rpcbind
$ sudo systemctl disable rpcbind

$ sudo systemctl stop postfix
$ sudo systemctl disable postfix
$ sudo systemctl stop sendmail
$ sudo systemctl disable sendmail

# init.d 기반일 경우
$ sudo /etc/rc.d/init.d/rpcbind stop
$ sudo /etc/rc.d/init.d/sendmail stop
$ ps -ef | grep rpc
  -- rpc.statd 프로세스 kill

su 명령어의 사용제한 설정

$ chmod 4750 /bin/su

Kernel 옵션 값 설정

net.ipv4.icmp_echo_ignore_broadcasts = 1

net.ipv4.icmp_ignore_bogus_error_responses = 1

net.ipv4.tcp_fin_timeout = 30

net.ipv4.tcp_keepalive_time = 180

net.ipv4.tcp_timestamps = 0

net.ipv4.tcp_syncookies = 1

net.ipv4.tcp_max_syn_backlog = 1280

net.ipv4.tcp_sack = 0

net.ipv4.tcp_window_scaling = 0

net.ipv4.conf.all.accept_redirects = 0

net.ipv4.conf.all.send_redirects = 0

net.ipv4.conf.all.rp_filter = 1

net.ipv4.conf.default.rp_filter = 1

net.ipv4.conf.all.log_martians = 1

net.ipv4.conf.all.accept_source_route = 0

net.ipv4.ip_local_port_range = 32768 61000

net.ipv4.ip_forward = 0

vm.bdflush = 100 1200 128 512 15 5000 500 1884 2

vm.buffermem = 80 10 60

kernel.sysrq = 1


##선택사항

net.ipv4.icmp_echo_ignore_all = 0

fs.file-max = 32768

시스템 오류 메시지 확인 방법

  • segfault, oom-killer OS 레벨 오류 메시지 확인
$ dmesg | tail
  • messages에서 커널과 OS 표준 프로세스 로그 확인
$ cat /var/log/messages | egrep -i "emerg|alert|crit|error|warn|fail"
  • secure 로그를 통해 ssh 연결실패 정보 확인 및 파악
$ cat /var/log/secure | tail
profile
Cloud Engineer@Plateer. 클라우드 상에서 엔지니어링을 재미있게 하는 엔지니어입니다.

0개의 댓글