Last active
February 9, 2025 12:51
-
-
Save mietzen/b05f050c774450247a4d1512ffaa1243 to your computer and use it in GitHub Desktop.
Proxmox Debian VM Template Setup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set +exo pipefail | |
# Call with: | |
# wget -qO - https://gist.githubusercontent.com/mietzen/b05f050c774450247a4d1512ffaa1243/raw/proxmox-debian-ct-template-setup.sh | \ | |
# | bash /dev/stdin $YOUR_USER_NAME | |
## Install deps | |
apt-get update | |
apt-get dist-upgrade -y | |
apt-get install sudo curl wget python3 -y | |
## User Setup | |
CT_USER=$1 | |
useradd -m -U -G sudo -s /usr/bin/bash ${CT_USER} | |
mkdir -p /home/${CT_USER}/.ssh | |
cp /root/.ssh/authorized_keys /home/${CT_USER}/.ssh/authorized_keys | |
chown -R ${CT_USER}:${CT_USER} /home/${CT_USER}/.ssh | |
chmod 700 /home/${CT_USER}/.ssh | |
chmod 600 /home/${CT_USER}/.ssh/authorized_keys | |
echo "${CT_USER} ALL=(ALL:ALL) NOPASSWD: ALL" | sudo tee /etc/sudoers.d/${CT_USER} | |
## No ssh root / password login | |
sed -i 's/^#PermitRootLogin.*/PermitRootLogin no/' /etc/ssh/sshd_config | |
sed -i 's/^#PasswordAuthentication.*/PasswordAuthentication no/' /etc/ssh/sshd_config | |
## Generate MOTD | |
rm -rf /etc/update-motd.d/* | |
cat << 'EOF' > /etc/update-motd.d/00-update-motd | |
#!/bin/bash | |
source /etc/os-release | |
load=$(cat /proc/loadavg | awk '{print $1}') | |
root_usage=$(df -h / | awk '/\// {print $(NF-1)}') | |
memory_usage=$(free -m | awk '/Mem:/ { total=$2 } /buffers\/cache/ { used=$3 } END { printf("%3.1f%%", used/total*100)}') | |
swap_usage=$(free -m | awk '/Swap/ { printf("%3.1f%%", "exit !$2;$3/$2*100") }') | |
users=$(users | wc -w) | |
time=$(uptime | grep -ohe 'up .*' | sed 's/,/\ hours/g' | awk '{ printf $2" "$3 }') | |
processes=$(ps aux | wc -l) | |
ip=$(ip addr | grep inet.*eth | sed 's/.*inet //' | sed 's/\/.*//' | head -n1) | |
pkgs=$(apt list --upgradable 2> /dev/null | grep 'upgradable' | wc -l) | |
echo $(date) | |
echo | |
echo -e "\033[1mWelcome to $(hostname) - ${ID^} ${VERSION_ID} $(uname -r)\033[0m" | |
echo | |
echo -e "System load:\t${load}\tIP Address:\t${ip}" | |
echo -e "Memory usage:\t${memory_usage}\tSystem uptime:\t${time}" | |
echo -e "Usage on /:\t${root_usage}\tSwap usage:\t${swap_usage}" | |
echo | |
if [ ${pkgs} -gt 0 ]; then | |
echo -e "\033[1;31mSystem needs ${pkgs} updates!\033[0m" | |
else | |
echo -e "\033[1;32mSystem is up to date!\033[0m" | |
fi | |
EOF | |
chmod +x /etc/update-motd.d/00-update-motd | |
echo "" > /etc/motd | |
## Generate Issue message | |
cat << EOF > /etc/issue | |
Debian GNU/Linux 12 \n \l | |
IP (eth0): \4{eth0} | |
EOF | |
## Cleanup | |
apt-get autoremove -y | |
apt-get autoclean -y | |
history -c |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment