fix: now fixed ssh problem

This commit is contained in:
robcholz
2026-02-06 21:15:57 -05:00
parent 1cb669be88
commit 27e5733c93
3 changed files with 66 additions and 30 deletions
+42 -28
View File
@@ -1,46 +1,60 @@
#!/bin/sh
set -eu
SSH_USER="__SSH_USER__"
SUDO_PASSWORD="__SUDO_PASSWORD__"
PROJECT_NAME="__PROJECT_NAME__"
KEY_PATH="__KEY_PATH__"
if [ -d /root/${PROJECT_NAME}/.vibebox ]; then
mount -t tmpfs tmpfs /root/${PROJECT_NAME}/.vibebox
# 1) tmpfs mount
TARGET="/root/${PROJECT_NAME}/.vibebox"
if [ -d "$TARGET" ] && ! mountpoint -q "$TARGET"; then
mount -t tmpfs tmpfs "$TARGET"
fi
if ! command -v sshd >/dev/null 2>&1; then
apt-get update && apt-get install -y openssh-server sudo
# 2)
if ! id -u "$SSH_USER" >/dev/null 2>&1; then
useradd -m -s /bin/bash -U "$SSH_USER"
usermod -aG sudo "$SSH_USER" || true
fi
systemctl enable ssh >/dev/null 2>&1 || true
id -u ${SSH_USER} >/dev/null 2>&1 || useradd -m -s /bin/bash ${SSH_USER}
echo "${SSH_USER}:${SUDO_PASSWORD}" | chpasswd
usermod -aG sudo ${SSH_USER}
install -d -m 700 /home/${SSH_USER}/.ssh
install -m 600 ${KEY_PATH} /home/${SSH_USER}/.ssh/authorized_keys
chown -R ${SSH_USER}:${SSH_USER} /home/${SSH_USER}/.ssh
rm -f /home/${SSH_USER}/.bash_logout
mkdir -p /etc/ssh/sshd_config.d
cat >/etc/ssh/sshd_config.d/vibebox.conf <<'VIBEBOX_SSHD'
PasswordAuthentication no
KbdInteractiveAuthentication no
ChallengeResponseAuthentication no
PubkeyAuthentication yes
PermitRootLogin no
AllowUsers __SSH_USER__
VIBEBOX_SSHD
systemctl restart ssh
install -d -m 700 -o "$SSH_USER" -g "$SSH_USER" "/home/${SSH_USER}/.ssh"
install -m 600 -o "$SSH_USER" -g "$SSH_USER" "$KEY_PATH" "/home/${SSH_USER}/.ssh/authorized_keys"
# 3)
systemctl start ssh >/dev/null 2>&1 || true
# 4)
i=0
while :; do
if ss -lnt 2>/dev/null | awk '{print $4}' | grep -qE '(:22)$'; then
break
fi
i=$((i+1))
[ "$i" -ge 40 ] && break # ~4s
sleep 0.1
done
echo VIBEBOX_SSH_READY
echo "=== generated network file ==="
sed -n '1,200p' /run/systemd/network/10-netplan-all-en.network || true
find_ip() {
if command -v ip >/dev/null 2>&1; then
ip -4 -o addr show scope global 2>/dev/null | awk '{print $4}' | cut -d/ -f1 | head -n 1
return
fi
if command -v hostname >/dev/null 2>&1; then
hostname -I 2>/dev/null | awk '{print $1}'
return
fi
}
while true; do
ip=$(ip -4 -o addr show scope global | awk '{print $4}' | cut -d/ -f1 | head -n 1)
i=0
while :; do
ip="$(find_ip || true)"
if [ -n "$ip" ]; then
echo VIBEBOX_IPV4=$ip
break
fi
sleep 1
i=$((i+1))
[ "$i" -ge 60 ] && break
sleep 0.5
done