prepare_security.sh 964 字节
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
#!/bin/bash

set -x

SELINUX="
SELINUX=disabled
"

LIMITS="
* soft nofile 65536
* hard nofile 65536
* soft nproc 131072
* hard nproc 131072
"

main() {
  if [[ -z ${VERIFY:-} ]]; then
    apply
  else
    verify
  fi
}

apply() {
  echo "Configuring Security"

  echo "$LIMITS" > /etc/security/limits.d/99_overrides.conf
  echo "$SELINUX" > /etc/selinux/config

  disable_iptables

  create_gpadmin

  generate_keys

  echo "Configuration Done"
}

disable_iptables() {
  /sbin/service iptables stop
  /sbin/chkconfig iptables off
}

create_gpadmin() {
  getent passwd gpadmin || useradd -m gpadmin
}

generate_keys() {
  for U in root gpadmin; do
    su $U -c "mkdir -p ~${U}/.ssh"
    su $U -c "[[ -f ~${U}/.ssh/id_rsa ]] || ssh-keygen -N '' -f ~${U}/.ssh/id_rsa"

    su $U -c "touch ~${U}/.ssh/authorized_keys"
    su $U -c "chmod 600 ~${U}/.ssh/authorized_keys"
  done
}

verify() {
  echo "Running ulimit to verify changes to limits"
  ulimit -a
}

main "$@"