2024-06-26 01:24:45 -04:00
#!/bin/sh
2022-11-20 16:41:17 -05:00
2024-01-20 03:09:48 -05:00
# Copyright (C) 2021-2024 Thien Tran
2023-09-27 03:56:28 -04:00
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
2023-03-11 12:53:28 -05:00
# You need to add either the non-subscription repo or the testing repo from the Proxmox WebUI after running this script.
2023-12-01 21:54:20 -05:00
output( ) {
2024-06-26 01:24:45 -04:00
printf '\e[1;34m%-6s\e[m\n' " ${ @ } "
2023-12-01 21:54:20 -05:00
}
2024-01-24 18:48:16 -05:00
# Compliance and updates
2023-12-07 19:15:05 -05:00
systemctl mask debug-shell.service
2023-12-07 18:44:55 -05:00
2024-01-24 18:48:16 -05:00
## Avoid phased updates
2024-02-01 04:09:40 -05:00
curl https://raw.githubusercontent.com/TommyTran732/Linux-Setup-Scripts/main/etc/apt/apt.conf.d/99sane-upgrades | tee /etc/apt/apt.conf.d/99sane-upgrades
2024-01-24 18:48:16 -05:00
2023-08-16 06:22:28 -04:00
# Setup NTS
2023-12-02 01:14:27 -05:00
rm -rf /etc/chrony/chrony.conf
curl https://raw.githubusercontent.com/GrapheneOS/infrastructure/main/chrony.conf | tee /etc/chrony/chrony.conf
systemctl restart chronyd
2023-08-16 06:22:28 -04:00
# Harden SSH
2024-02-07 11:52:52 -05:00
curl https://raw.githubusercontent.com/TommyTran732/Linux-Setup-Scripts/main/etc/ssh/sshd_config.d/10-custom.conf | tee /etc/ssh/sshd_config.d/10-custom.conf
2024-07-01 16:45:00 -04:00
sed -i 's/PermitRootLogin no/PermitRootLogin yes/g' /etc/ssh/sshd_config.d/10-custom.conf
2024-02-07 11:52:52 -05:00
curl https://raw.githubusercontent.com/TommyTran732/Linux-Setup-Scripts/main/etc/ssh/ssh_config.d/10-custom.conf | tee /etc/ssh/ssh_config.d/10-custom.conf
2023-12-02 01:14:27 -05:00
mkdir -p /etc/systemd/system/ssh.service.d
curl https://raw.githubusercontent.com/GrapheneOS/infrastructure/main/systemd/system/sshd.service.d/local.conf | tee /etc/systemd/system/ssh.service.d/override.conf
systemctl daemon-reload
systemctl restart sshd
2023-01-25 06:33:56 -05:00
2023-08-16 06:22:28 -04:00
# Setup repositories
2024-02-03 08:46:19 -05:00
sed -i '1 {s/^/# /}' /etc/apt/sources.list.d/pve-enterprise.list
sed -i '1 {s/^/# /}' /etc/apt/sources.list.d/ceph.list
2022-11-20 17:05:22 -05:00
2023-08-22 19:54:08 -04:00
echo ' deb https://deb.debian.org/debian/ bookworm main contrib non-free non-free-firmware
2022-11-20 17:05:22 -05:00
2024-02-03 08:18:58 -05:00
deb https://deb.debian.org/debian-security/ bookworm-security main contrib non-free non-free-firmware
2022-11-20 17:05:22 -05:00
2023-08-22 19:54:08 -04:00
deb https://deb.debian.org/debian/ bookworm-updates main contrib non-free non-free-firmware
deb https://deb.debian.org/debian/ bookworm-backports main contrib non-free non-free-firmware
2022-11-20 17:05:22 -05:00
2023-12-02 01:14:27 -05:00
deb http://download.proxmox.com/debian/pve bookworm pve-no-subscription' | tee /etc/apt/sources.list
2022-11-20 17:05:22 -05:00
2024-02-03 08:46:19 -05:00
echo 'deb http://download.proxmox.com/debian/ceph-quincy bookworm no-subscription' | tee -a /etc/apt/sources.list.d/ceph.list
2023-12-01 20:59:29 -05:00
2024-02-01 04:07:23 -05:00
# Update packages
apt update
apt full-upgrade -y
apt autoremove -y
2024-01-24 18:48:16 -05:00
# Install packages
apt install -y intel-microcode tuned fwupd dropbear-initramfs
2022-11-20 16:41:17 -05:00
### This part assumes that you are using systemd-boot
2024-06-26 01:24:45 -04:00
echo " mitigations=auto,nosmt spectre_v2=on spectre_bhi=on spec_store_bypass_disable=on tsx=off kvm.nx_huge_pages=force nosmt=force l1d_flush=on spec_rstack_overflow=safe-ret gather_data_sampling=force reg_file_data_sampling=on random.trust_bootloader=off random.trust_cpu=off intel_iommu=on amd_iommu=force_isolation efi=disable_early_pci_dma iommu=force iommu.passthrough=0 iommu.strict=1 slab_nomerge init_on_alloc=1 init_on_free=1 pti=on vsyscall=none ia32_emulation=0 page_alloc.shuffle=1 randomize_kstack_offset=on debugfs=off $( cat /etc/kernel/cmdline) " > /etc/kernel/cmdline
2023-12-02 01:14:27 -05:00
proxmox-boot-tool refresh
2022-11-20 16:41:17 -05:00
###
2023-08-16 06:22:28 -04:00
# Kernel hardening
2024-06-04 08:33:52 -04:00
curl https://raw.githubusercontent.com/secureblue/secureblue/live/config/files/usr/etc/modprobe.d/blacklist.conf | tee /etc/modprobe.d/server-blacklist.conf
sed -i 's/kernel_io_uring_disable = 2/#ernel_io_uring_disable = 2/g'
curl https://raw.githubusercontent.com/TommyTran732/Linux-Setup-Scripts/main/etc/sysctl.d/99-server.conf | tee /etc/sysctl.d/99-server.conf
2024-02-13 19:16:33 -05:00
sysctl -p
2022-11-20 16:41:17 -05:00
2024-02-13 19:16:33 -05:00
# Rebuild initramfs
update-initramfs -u
# Disable coredump
2024-06-04 17:29:50 -04:00
unpriv curl https://raw.githubusercontent.com/TommyTran732/Linux-Setup-Scripts/main/etc/security/limits.d/30-disable-coredump.conf | tee /etc/security/limits.d/30-disable-coredump.conf
2024-06-04 08:33:52 -04:00
mkdir -p /etc/systemd/coredump.conf.d
2024-06-04 17:29:50 -04:00
unpriv curl https://raw.githubusercontent.com/TommyTran732/Linux-Setup-Scripts/main/etc/systemd/coredump.conf.d/disable.conf | tee /etc/systemd/coredump.conf.d/disable.conf
2024-02-13 19:16:33 -05:00
# Harden SSH
2023-12-02 01:14:27 -05:00
sed -i 's/#GSSAPIAuthentication no/GSSAPIAuthentication no/g' /etc/ssh/sshd_config
2022-11-20 16:41:17 -05:00
2023-08-16 06:22:28 -04:00
# Setup automatic updates
2023-12-02 01:14:27 -05:00
mkdir -p /etc/systemd/system/pve-daily-update.service.d
2022-11-20 16:41:17 -05:00
echo ' [ Service]
2023-12-02 01:14:27 -05:00
ExecStart = /usr/bin/pveupgrade' | tee /etc/systemd/system/pve-daily-update.service.d/override.conf
systemctl daemon-reload
systemctl enable --now pve-daily-update.timer
2022-11-20 16:41:17 -05:00
2023-12-02 01:14:27 -05:00
mkdir -p /etc/systemd/system/fwupd-refresh.service.d
2022-11-20 16:41:17 -05:00
echo ' [ Service]
2023-07-05 10:39:16 -04:00
ExecStart = /usr/bin/fwupdmgr update' | tee /etc/systemd/system/fwupd-refresh.service.d/override.conf
2023-12-02 01:14:27 -05:00
systemctl daemon-reload
systemctl enable --now fwupd-refresh.timer
2022-11-20 16:41:17 -05:00
2023-03-10 13:39:57 -05:00
# Disable Nagging
2023-12-02 01:14:27 -05:00
sed -Ezi.bak "s/(Ext.Msg.show\(\{\s+title: gettext\('No valid sub)/void\(\{ \/\/\1/g" /usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js
2023-03-10 13:39:57 -05:00
2023-12-02 01:14:27 -05:00
systemctl restart pveproxy.service
2023-07-07 05:41:36 -04:00
2023-08-16 06:22:28 -04:00
# Setup tuned
2023-12-02 01:14:27 -05:00
tuned-adm profile virtual-host
2023-08-16 06:22:28 -04:00
2023-07-07 05:41:36 -04:00
# Enable fstrim.timer
2024-07-01 16:45:00 -04:00
systemctl enable --now fstrim.timer