51 lines
2.1 KiB
Bash
Executable File
51 lines
2.1 KiB
Bash
Executable File
#!/bin/bash
|
||
# ============================================================
|
||
# 🧰 Gitea SSH Fix Script (Version 3)
|
||
# Führt vollständige Reparatur von SSH-Keys, Hooks & Rechten durch
|
||
# ============================================================
|
||
|
||
set -euo pipefail
|
||
grn='\e[32m'; red='\e[31m'; yel='\e[33m'; nc='\e[0m'
|
||
|
||
echo -e "${grn}🔧 Starte Gitea SSH-Reparatur...${nc}"
|
||
|
||
# 1️⃣ Gitea-Binary prüfen
|
||
GITEA_BIN=$(command -v gitea || echo "/usr/local/bin/gitea")
|
||
echo -e "${grn}➡ Verwende Gitea-Binary:${nc} $GITEA_BIN"
|
||
|
||
# 2️⃣ Gitea stoppen
|
||
echo -e "${yel}⏹ Stoppe Gitea-Service...${nc}"
|
||
systemctl stop gitea || echo -e "${red}⚠️ Konnte Gitea nicht stoppen (evtl. nicht aktiv).${nc}"
|
||
|
||
# 3️⃣ Hooks & Keys regenerieren (richtig: als Benutzer 'git')
|
||
echo -e "${grn}♻️ Regeneriere Hooks und Keys...${nc}"
|
||
sudo -u git "$GITEA_BIN" --config /etc/gitea/app.ini --work-path /var/lib/gitea admin regenerate hooks
|
||
sudo -u git "$GITEA_BIN" --config /etc/gitea/app.ini --work-path /var/lib/gitea admin regenerate keys
|
||
|
||
# 4️⃣ Berechtigungen für .ssh korrigieren
|
||
echo -e "${grn}🧱 Setze Berechtigungen für .ssh...${nc}"
|
||
chown -R git:git /home/git/.ssh
|
||
chmod 700 /home/git/.ssh
|
||
chmod 600 /home/git/.ssh/authorized_keys
|
||
|
||
# 5️⃣ authorized_keys prüfen
|
||
if ! grep -q "command=" /home/git/.ssh/authorized_keys; then
|
||
echo -e "${yel}⚠️ Kein 'command='-Eintrag gefunden – ergänze Gitea-Zeile...${nc}"
|
||
FIRST_KEY=$(head -n 1 /home/git/.ssh/authorized_keys | awk '{print $NF}')
|
||
echo "command=\"$GITEA_BIN --config=/etc/gitea/app.ini serv key-1\",no-port-forwarding,no-agent-forwarding,no-pty ssh-ed25519 $FIRST_KEY" > /home/git/.ssh/authorized_keys
|
||
chown git:git /home/git/.ssh/authorized_keys
|
||
chmod 600 /home/git/.ssh/authorized_keys
|
||
else
|
||
echo -e "${grn}✅ authorized_keys sieht gut aus.${nc}"
|
||
fi
|
||
|
||
# 6️⃣ Gitea starten
|
||
echo -e "${grn}🚀 Starte Gitea neu...${nc}"
|
||
systemctl start gitea
|
||
|
||
# 7️⃣ SSH-Test lokal
|
||
echo -e "${yel}🔍 Kurzer SSH-Test (lokal)...${nc}"
|
||
sudo -u git ssh -T git@localhost || true
|
||
|
||
echo -e "\n${grn}✅ Gitea SSH-Fix abgeschlossen.${nc}"
|
||
echo -e "Teste jetzt bitte extern mit:\n ssh -T git@illg.me\noder\n git push" |