#!/usr/bin/env bash # Basic Server Security Hardening # Min. Requirement : GNU/Linux Ubuntu 18.04 # Last Build : 06/08/2022 # Author : MasEDI.Net (me@masedi.net) # Since Version : 2.6.4 # Include helper functions. if [[ "$(type -t run)" != "function" ]]; then BASE_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd ) # shellcheck disable=SC1091 . "${BASE_DIR}/utils.sh" # Make sure only root can run this installer script. requires_root "$@" # Make sure only supported distribution can run this installer script. preflight_system_check fi function init_server_optimization() { ### Create and enable swap ### if [[ "${ENABLE_SWAP}" == true ]]; then enable_swap fi ### Create and enable sysctl ### echo "Configure kernel optimization..." # Adjust swappiness, default Ubuntu set to 60 # meaning that the swap file will be used fairly often if the memory usage is # around half RAM, for production servers you may need to set a lower value. if [[ "${ENABLE_SWAP}" == true ]]; then echo "Adjusting swappiness..." if [[ $(cat /proc/sys/vm/swappiness) -gt 10 ]]; then if [[ ${DRYRUN} != true ]]; then run sed -i "s/vm.swappiness/#vm.swappiness/" /etc/sysctl.conf cat >> /etc/sysctl.conf <> /etc/sysctl.conf <> /etc/sysctl.conf <> /etc/sysctl.conf < /sys/kernel/mm/transparent_hugepage/enabled" if [[ ! -f /etc/rc.local ]]; then run touch /etc/rc.local fi # Make the change persistent. cat >> /etc/rc.local < /sys/kernel/mm/transparent_hugepage/enabled EOL fi run sysctl -p } echo "[LEMPer Stack Basic Server Optimization]" # Start running things from a call at the end so if this script is executed # after a partial download it doesn't do anything. init_server_optimization "$@"