Compare commits

..

22 Commits

Author SHA1 Message Date
d69b39f20c Merge pull request 'Update bootstrap.sh' (#20) from dev into prod
Reviewed-on: #20
2026-07-26 16:51:20 +02:00
44b0b866b8 Update bootstrap.sh 2026-07-26 16:51:03 +02:00
6092772d88 Merge pull request 'Update bootstrap.sh' (#19) from dev into prod
Reviewed-on: #19
2026-07-26 16:28:32 +02:00
35a7d7888f Update bootstrap.sh 2026-07-26 16:27:55 +02:00
629c54b21c Merge pull request 'Update bootstrap.sh' (#18) from dev into prod
Reviewed-on: #18
2026-07-23 17:50:25 +02:00
2d5f13ba98 Update bootstrap.sh 2026-07-23 17:50:15 +02:00
448c5516c9 Merge pull request 'Update bootstrap.sh' (#17) from dev into prod
Reviewed-on: #17
2026-07-23 17:41:25 +02:00
1a35d6d60a Update bootstrap.sh 2026-07-23 17:41:06 +02:00
ed3d309691 Merge pull request 'Update bootstrap.sh' (#16) from dev into prod
Reviewed-on: #16
2026-07-01 22:33:42 +02:00
521f77cf5b Update bootstrap.sh 2026-07-01 22:33:25 +02:00
b5edca7adf Merge pull request 'Update bootstrap.sh' (#15) from dev into prod
Reviewed-on: #15
2026-06-12 18:18:02 +02:00
018ce95617 Update bootstrap.sh 2026-06-12 18:17:54 +02:00
7deb076d3d Merge pull request 'Update bootstrap.sh' (#14) from dev into prod
Reviewed-on: #14
2026-06-12 18:11:50 +02:00
ce9e345d37 Update bootstrap.sh 2026-06-12 18:11:39 +02:00
668ea5c5e2 Merge pull request 'Update bootstrap.sh' (#13) from dev into prod
Reviewed-on: #13
2026-06-12 17:57:10 +02:00
8dd3bbe8a3 Update bootstrap.sh 2026-06-12 17:57:02 +02:00
401df4602a Merge pull request 'Update bootstrap.sh' (#12) from dev into prod
Reviewed-on: #12
2026-06-12 17:54:34 +02:00
89d496bfdd Update bootstrap.sh 2026-06-12 17:54:25 +02:00
7fcaf9a84d Merge pull request 'Update bootstrap.sh' (#11) from dev into prod
Reviewed-on: #11
2026-06-12 17:53:10 +02:00
003dc11383 Update bootstrap.sh 2026-06-12 17:53:01 +02:00
a0faa7629d Merge pull request 'Update bootstrap.sh' (#10) from dev into prod
Reviewed-on: #10
2026-06-12 17:40:50 +02:00
fa937ab8aa Update bootstrap.sh 2026-06-12 17:40:40 +02:00

View File

@@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
### 1. VARIABLES #################. VARIABLES
MOTD="/etc/update-motd.d/01-custom" MOTD="/etc/update-motd.d/01-custom"
REBOOTBIN="/usr/sbin/reboot" REBOOTBIN="/usr/sbin/reboot"
REBOOTBINOLD="/usr/sbin/reboot.old" REBOOTBINOLD="/usr/sbin/reboot.old"
@@ -10,16 +10,20 @@ REBOOTHANDLER="/root/scripts/reboot_handler.sh"
CRONTABTMP="/tmp/crontab.root.tmp" CRONTABTMP="/tmp/crontab.root.tmp"
HOSTNAME=$(hostname) HOSTNAME=$(hostname)
KEYFILE="/root/.ssh/$HOSTNAME" KEYFILE="/root/.ssh/$HOSTNAME"
MOTD_TEMP="/etc/update-motd/02-temp" TEMP_SCRIPT="/root/firstlogin.sh"
TEMP_SCRIPT_WRAPPER="/root/firstloginwrapper.sh"
TEMP_SCRIPT_CLEANER="/root/firstlogincleaner.sh"
## 2. ALIASES #################. ALIASES
echo "alias ll='ls -l --color=auto'" >> ~/.bashrc echo "alias ll='ls -l --color=auto'" >> ~/.bashrc
echo "alias l='ls -lAh --color=auto'" >> ~/.bashrc echo "alias l='ls -lAh --color=auto'" >> ~/.bashrc
echo "" >> ~/.bashrc
echo 'PS1="\u\[\e[0m\]@\[\e[31m\]\h\[\e[0m\]:\[\e[34m\]\w\[\e[0m\]# "' >> ~/.bashrc
source ~/.bashrc source ~/.bashrc
## 3. UPDATE & ESSENTIALS #################. UPDATE & ESSENTIALS
apt update && apt -o Dpkg::Options::="--force-confold" upgrade -y apt update && apt -o Dpkg::Options::="--force-confold" upgrade -y
apt install -y vim inxi fastfetch htop ncdu net-tools apt install -y vim inxi fastfetch htop ncdu net-tools
@@ -56,29 +60,27 @@ fi
EOF EOF
chmod +x $MOTD chmod +x $MOTD
### 4. Création du script first-login #################. Création du script first-login
cat << 'EOF' > $TEMP_SCRIPT
cat << 'EOF' > $MOTD_TEMP
#!/bin/bash #!/bin/bash
RED='\033[0;31m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
HOSTNAME=$(hostname) HOSTNAME=$(hostname)
KEYFILE="/root/.ssh/$HOSTNAME" KEYFILE="/root/.ssh/$HOSTNAME"
echo echo
echo -e "${BLUE}===============================${NC}" echo "==============================="
echo -e "${BLUE} Clé privée SSH à conserver !${NC}" echo " Clé privée SSH à conserver !"
echo -e "${BLUE}===============================${NC}" echo "==============================="
echo echo
cat "${KEYFILE}"
# Affichage dans TON shell
cat "$KEYFILE"
echo echo
echo "${BLUE}===============================${NC}" echo "==============================="
# Suppression de la clé privée # Suppression de la clé privée
rm -f "${KEYFILE}" rm -f "$KEYFILE"
# Durcissement SSH # Durcissement SSH
sed -i 's/^#\?PubkeyAuthentication.*/PubkeyAuthentication yes/' /etc/ssh/sshd_config sed -i 's/^#\?PubkeyAuthentication.*/PubkeyAuthentication yes/' /etc/ssh/sshd_config
@@ -87,16 +89,56 @@ sed -i 's/^#\?PermitRootLogin.*/PermitRootLogin prohibit-password/' /etc/ssh/ssh
sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication no/' /etc/ssh/sshd_config sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication no/' /etc/ssh/sshd_config
systemctl restart sshd systemctl restart sshd
rm -fr $MOTD_TEMP
EOF
chmod +x $MOTD_TEMP
### 5. Hardening binaries # Nettoyage différé
nohup /root/firstlogincleaner.sh >/dev/null 2>&1 &
exit 0
EOF
chmod +x $TEMP_SCRIPT
cat << 'EOF' > $TEMP_SCRIPT_WRAPPER
#!/bin/bash
if [ -f /root/firstlogin.sh ]; then
/root/firstlogin.sh
fi
exit 0
EOF
chmod +x $TEMP_SCRIPT_WRAPPER
cat << 'EOF' > $TEMP_SCRIPT_CLEANER
#!/bin/bash
# Attendre la fin du login
sleep 2
# Supprimer la ligne PAM
sed -i '/firstloginwrapper.sh/d' /etc/pam.d/sshd
# Supprimer les scripts
rm -f /root/firstlogin.sh
rm -f /root/firstloginwrapper.sh
rm -f /root/firstlogincleaner.sh
rm -f /root/bootstrap.sh
exit 0
EOF
chmod +x $TEMP_SCRIPT_CLEANER
echo "auth optional pam_exec.so stdout /root/firstloginwrapper.sh" >> /etc/pam.d/sshd
#################. Hardening binaries
# REBOOT WRAPPER # REBOOT WRAPPER
mv $REBOOTBIN $REBOOTBINOLD mv $REBOOTBIN $REBOOTBINOLD
cat << 'EOF' > $REBOOTBIN cat << 'EOF' > $REBOOTBIN
#!/bin/bash #!/bin/bash
touch /var/log/restart-flag touch /var/log/restart-flag
echo "[REBOOT] Rebooting server..."
sleep 1 sleep 1
/usr/sbin/reboot.old /usr/sbin/reboot.old
EOF EOF
@@ -106,13 +148,14 @@ chmod +x $REBOOTBIN
cat << 'EOF' > $SHUTBIN cat << 'EOF' > $SHUTBIN
#!/bin/bash #!/bin/bash
touch /var/log/restart-flag touch /var/log/restart-flag
echo "[SHUTDOWN] Stopping server..."
sleep 1 sleep 1
shutdown -h now shutdown -h now
EOF EOF
chmod +x $SHUTBIN chmod +x $SHUTBIN
### 6. REBOOT HANDLER #################. REBOOT HANDLER
mkdir -p $SCRIPTSDIR mkdir -p $SCRIPTSDIR
cat << 'EOF' > $REBOOTHANDLER cat << 'EOF' > $REBOOTHANDLER
#!/bin/bash #!/bin/bash
@@ -168,3 +211,8 @@ ssh-keygen -t ed25519 -C "$HOSTNAME" -f "$KEYFILE" -N ""
# Ajouter la clé publique dans authorized_keys # Ajouter la clé publique dans authorized_keys
cat "${KEYFILE}.pub" >> /root/.ssh/authorized_keys cat "${KEYFILE}.pub" >> /root/.ssh/authorized_keys
chmod 600 /root/.ssh/authorized_keys chmod 600 /root/.ssh/authorized_keys
rm -fr /etc/systemd/system/bootstrap.service
rm -fr /etc/systemd/system/multi-user.target.wants/bootstrap.service
rm -fr /root/run-bootstrap.sh
systemctl daemon-reload