2023-06-06 01:54:42 -04:00
#!/bin/bash
2023-09-27 03:56:28 -04:00
# Copyright (C) 2023 Thien Tran
#
# 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-06-06 01:54:42 -04:00
#Please note that this is how I PERSONALLY setup my computer - I do some stuff such as not using anything to download GNOME extensions from extensions.gnome.org and installing the extensions as a package instead
2023-08-22 18:49:44 -04:00
##The script assumes you already have Ubuntu Pro activated
2023-06-06 01:54:42 -04:00
2023-12-01 21:54:20 -05:00
output( ) {
echo -e '\e[36m' $1 '\e[0m' ;
}
2023-08-22 20:46:56 -04:00
#Compliance and updates
2023-06-06 18:04:04 -04:00
sudo ua enable usg
2023-08-22 20:46:56 -04:00
sudo apt update -y
sudo apt full-upgrade -y
2023-06-06 18:04:04 -04:00
sudo apt install -y usg
2023-08-22 20:46:56 -04:00
sudo apt autoremove -y
2023-08-28 04:06:14 -04:00
sudo usg fix cis_level2_workstation
2023-06-06 18:04:04 -04:00
2023-08-16 06:22:28 -04:00
# Remove AIDE
sudo apt purge -y aide*
2023-11-10 18:39:09 -05:00
# Allow su which is disabled by CIS
2023-06-06 18:04:04 -04:00
sudo sed -i 's/auth required pam_wheel.so use_uid group=sugroup//g' /etc/pam.d/su
2023-08-16 06:22:28 -04:00
# Setting umask to 077
2023-06-06 01:54:42 -04:00
umask 077
sudo sed -ie '/^DIR_MODE=/ s/=[0-9]*\+/=0700/' /etc/adduser.conf
sudo sed -ie '/^UMASK\s\+/ s/022/077/' /etc/login.defs
sudo sed -i 's/USERGROUPS_ENAB yes/USERGROUPS_ENAB no/g' /etc/login.defs
echo "umask 077" | sudo tee --append /etc/profile
2023-08-16 06:22:28 -04:00
# Setup NTS
sudo systemctl disable systemd-timesyncd
2023-08-28 04:30:35 -04:00
sudo apt install -y curl chrony
2023-12-02 01:04:02 -05:00
curl https://raw.githubusercontent.com/GrapheneOS/infrastructure/main/chrony.conf | sudo tee /etc/chrony/chrony.conf
2023-08-16 06:22:28 -04:00
sudo systemctl restart chronyd
# Setup UFW
#UFW Snap is strictly confined, unlike its .deb counterpart
sudo apt purge -y ufw
sudo snap install ufw
sudo ufw enable
# Harden SSH
echo "GSSAPIAuthentication no" | sudo tee /etc/ssh/ssh_config.d/10-custom.conf
echo "VerifyHostKeyDNS yes" | sudo tee -a /etc/ssh/ssh_config.d/10-custom.conf
sudo chmod 644 /etc/ssh/ssh_config.d/10-custom.conf
# Kernel hardening
2023-12-02 01:04:02 -05:00
curl https://raw.githubusercontent.com/Kicksecure/security-misc/master/etc/modprobe.d/30_security-misc.conf | sudo tee /etc/modprobe.d/30_security-misc.conf
curl https://raw.githubusercontent.com/Kicksecure/security-misc/master/usr/lib/sysctl.d/990-security-misc.conf | sudo tee /etc/sysctl.d/990-security-misc.conf
curl https://raw.githubusercontent.com/Kicksecure/security-misc/master/usr/lib/sysctl.d/30_silent-kernel-printk.conf | sudo tee /etc/sysctl.d/30_silent-kernel-printk.conf
curl https://raw.githubusercontent.com/Kicksecure/security-misc/master/usr/lib/sysctl.d/30_security-misc_kexec-disable.conf | sudo tee /etc/sysctl.d/30_security-misc_kexec-disable.conf
2023-11-15 16:12:25 -05:00
sudo sed -i 's/kernel.yama.ptrace_scope=2/kernel.yama.ptrace_scope=3/g' /etc/sysctl.d/990-security-misc.conf
2023-09-27 02:03:35 -04:00
sudo sysctl -p
# Rebuild initramfs
sudo update-initramfs -u
# Disable telemetry
sudo systemctl stop apport.service
sudo systemctl disable apport.service
sudo systemctl mask apport.service
sudo systemctl stop whoopsie.service
sudo systemctl disable whoopsie.service
sudo systemctl mask whoopsie.service
2023-06-06 01:54:42 -04:00
2023-08-16 06:22:28 -04:00
# Systemd Hardening
2023-06-06 01:54:42 -04:00
sudo mkdir -p /etc/systemd/system/NetworkManager.service.d
2023-12-02 01:04:02 -05:00
curl https://gitlab.com/divested/brace/-/raw/master/brace/usr/lib/systemd/system/NetworkManager.service.d/99-brace.conf | sudo tee /etc/systemd/system/NetworkManager.service.d/99-brace.conf
2023-06-06 01:54:42 -04:00
sudo mkdir -p /etc/systemd/system/irqbalance.service.d
2023-12-02 01:04:02 -05:00
curl https://gitlab.com/divested/brace/-/raw/master/brace/usr/lib/systemd/system/irqbalance.service.d/99-brace.conf | sudo tee /etc/systemd/system/irqbalance.service.d/99-brace.conf
2023-06-06 02:36:44 -04:00
2023-06-06 02:57:50 -04:00
# Disable automount
2023-11-11 06:00:27 -05:00
curl https://raw.githubusercontent.com/TommyTran732/Linux-Setup-Script/main/etc/dconf/db/local.d/automount-disable -o /etc/dconf/db/local.d/automount-disable
curl curl https://raw.githubusercontent.com/TommyTran732/Linux-Setup-Script/main/etc/dconf/db/local.d/locks/automount-disable -o /etc/dconf/db/local.d/locks/automount-disable
2023-06-06 02:57:50 -04:00
sudo dconf update
2023-08-16 06:22:28 -04:00
# Disable crash reports
2023-06-22 07:43:34 -04:00
echo ' [ com/ubuntu/update-notifier]
show-apport-crashes= false' | sudo tee /etc/dconf/db/local.d/disable-apport-crashes
echo 'com/ubuntu/update-notifier/show-apport-crashes' | sudo tee /etc/dconf/db/local.d/locks/disable-apport-crashes
2023-06-22 07:44:37 -04:00
sudo dconf update
2023-06-06 01:54:42 -04:00
ubuntu-report -f send no
sudo systemctl stop apport.service
sudo systemctl disable apport.service
sudo systemctl mask apport.service
sudo systemctl stop whoopsie.service
sudo systemctl disable whoopsie.service
sudo systemctl mask whoopsie.service
2023-08-16 06:22:28 -04:00
# Update packages and firmware
2023-06-06 02:00:57 -04:00
sudo apt update -y
sudo apt full-upgrade -y
sudo fwupdmgr get-devices
sudo fwupdmgr refresh --force
sudo fwupdmgr get-updates -y
sudo fwupdmgr update -y
2023-08-16 06:22:28 -04:00
# Remove unneeded packages
2023-06-22 20:13:04 -04:00
sudo apt purge -y cups* eog gedit firefox* gnome-calculator gnome-characters* gnome-font-viewer gnome-logs gnome-power-manager gnome-shell-extension-prefs seahorse tcpdump whoopsie
2023-06-06 05:13:25 -04:00
sudo apt autoremove -y
2023-06-22 20:13:55 -04:00
sudo snap remove firefox
2023-06-06 01:54:42 -04:00
2023-08-16 06:22:28 -04:00
# Install packages that I use
2023-06-06 04:21:44 -04:00
sudo apt install -y git-core gnome-text-editor
2023-06-06 23:36:17 -04:00
sudo snap install eog
2023-06-06 02:06:15 -04:00
2023-11-10 18:39:09 -05:00
# Setup Networking
2023-12-02 01:04:02 -05:00
curl https://raw.githubusercontent.com/TommyTran732/Linux-Setup-Script/main/etc/NetworkManager/conf.d/00-macrandomize.conf | sudo tee /etc/NetworkManager/conf.d/00-macrandomize.conf
curl https://raw.githubusercontent.com/TommyTran732/Linux-Setup-Script/main/etc/NetworkManager/conf.d/01-transient-hostname.conf | sudo tee /etc/NetworkManager/conf.d/01-transient-hostname.conf
2023-11-10 18:39:09 -05:00
sudo nmcli general reload conf
sudo hostnamectl hostname 'localhost'
sudo hostnamectl --transient hostname ''
2023-07-07 05:41:36 -04:00
# Enable fstrim.timer
2023-08-22 20:46:56 -04:00
sudo apt install tuned -y
2023-08-28 04:06:14 -04:00
sudo systemctl enable --now fstrim.timer