Linux初期セキュリティ設定


設定方法
sshd接続とルート接続/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 외 전체차단
特定のサービスポートをブロック
  • SSHBreutForce、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-kill OSレベルエラーメッセージ
  • を確認
    $ dmesg | tail
  • メールのカーネルとOS標準プロセスログ
  • を確認します.
    $ cat /var/log/messages | egrep -i "emerg|alert|crit|error|warn|fail"
  • セキュリティログによるssh接続失敗情報
  • の表示と理解
    $ cat /var/log/secure | tail