diff --git a/docs/kugetsu-setup.md b/docs/kugetsu-setup.md index a0098cd..aa3d77b 100644 --- a/docs/kugetsu-setup.md +++ b/docs/kugetsu-setup.md @@ -26,16 +26,23 @@ This guide covers setting up a server/container with kugetsu for remote agent in ### Incus ```bash -# Create container +# Create container (Debian/Ubuntu) incus launch images:debian/12 +# Or create Fedora container +incus launch images:fedora/43 + # Or use an existing container incus exec -- bash -# Ensure systemd is installed (Debian/Ubuntu) +# Ensure systemd is installed +# For Debian/Ubuntu: incus exec -- apt-get update incus exec -- apt-get install -y systemd +# For Fedora: +incus exec -- dnf install -y systemd + # Enable systemd in container (Incus specific - verify with your setup) incus config set security.syscalls.intercept.systemd true @@ -57,16 +64,33 @@ bash skills/kugetsu/scripts/sshd-setup.sh Replace `` with your preferred username, or omit to use default `kugetsu`. +**The script automatically detects your OS and installs the correct packages.** + +Supported OSes: Debian, Ubuntu, Fedora, RHEL, CentOS + ### Manual Setup If you prefer to set up SSH manually: #### 1. Install openssh-server +**Debian/Ubuntu:** ```bash apt-get update && apt-get install -y openssh-server sudo ``` +**Fedora/RHEL/CentOS:** +```bash +dnf install -y openssh-server sudo +``` + +#### 2. Verify installation + +```bash +which sshd +sshd -V +``` + #### 2. Create non-root user ```bash diff --git a/skills/kugetsu/scripts/kugetsu-install.sh b/skills/kugetsu/scripts/kugetsu-install.sh index 6ecec37..767cc6b 100755 --- a/skills/kugetsu/scripts/kugetsu-install.sh +++ b/skills/kugetsu/scripts/kugetsu-install.sh @@ -38,6 +38,14 @@ add_to_shell "$HOME/.bashrc" add_to_shell "$HOME/.zshrc" echo "" +echo "=== Verifying installation ===" +if [ ! -f "$BIN_DIR/kugetsu" ]; then + echo "ERROR: kugetsu was not installed correctly." + exit 1 +fi +echo "kugetsu installed at: $BIN_DIR/kugetsu" +echo "" + echo "Installation complete!" echo "" echo "Run this to start using kugetsu immediately:" diff --git a/skills/kugetsu/scripts/sshd-setup.sh b/skills/kugetsu/scripts/sshd-setup.sh index 1eca205..a9588e5 100644 --- a/skills/kugetsu/scripts/sshd-setup.sh +++ b/skills/kugetsu/scripts/sshd-setup.sh @@ -7,12 +7,44 @@ echo "=== kugetsu SSH Setup ===" echo "Target user: $USERNAME" echo "" +detect_os() { + if [ -f /etc/os-release ]; then + . /etc/os-release + case "$ID" in + debian|ubuntu|"noble"|"jammy"|"focal"|"bionic"|"bullseye"|"bookworm"|"trixie"|"sid") + echo "debian" + ;; + fedora|rhel|centos|rocky|alma) + echo "fedora" + ;; + *) + echo "unknown" + ;; + esac + else + echo "unknown" + fi +} + +OS_TYPE=$(detect_os) +echo "Detected OS: $OS_TYPE" + if ! command -v systemctl &> /dev/null; then echo "ERROR: systemd not found." echo "" echo "This script requires systemd to be installed and running inside the container." echo "Please install systemd first:" - echo " apt-get update && apt-get install -y systemd" + case "$OS_TYPE" in + debian) + echo " apt-get update && apt-get install -y systemd" + ;; + fedora) + echo " dnf install -y systemd" + ;; + *) + echo " Install systemd using your package manager" + ;; + esac echo "" echo "If you are running in a container that doesn't support systemd, consider:" echo " - Using a container image with systemd support" @@ -20,13 +52,36 @@ if ! command -v systemctl &> /dev/null; then exit 1 fi -echo "[1/6] Updating package lists..." -apt-get update -qq +echo "" +echo "=== Step 1: Install openssh-server ===" +case "$OS_TYPE" in + debian) + echo "Using apt-get (Debian/Ubuntu)..." + apt-get update -qq + apt-get install -y -qq openssh-server sudo + ;; + fedora) + echo "Using dnf (Fedora/RHEL)..." + dnf install -y -q openssh-server sudo + ;; + *) + echo "ERROR: Unsupported OS. Please install openssh-server and sudo manually." + exit 1 + ;; +esac -echo "[2/6] Installing openssh-server..." -apt-get install -y -qq openssh-server sudo +echo "" +echo "=== Step 2: Verify installation ===" +if ! command -v sshd &> /dev/null; then + echo "ERROR: sshd installation failed." + echo "Please verify openssh-server was installed correctly." + exit 1 +fi +echo "sshd binary: $(which sshd)" +echo "sshd version: $(sshd -V 2>&1 | head -1)" -echo "[3/6] Creating user '$USERNAME' if not exists..." +echo "" +echo "=== Step 3: Create user '$USERNAME' ===" if ! id "$USERNAME" &> /dev/null; then useradd -m -s /bin/bash "$USERNAME" echo "User '$USERNAME' created." @@ -34,27 +89,40 @@ else echo "User '$USERNAME' already exists." fi -echo "[4/6] Configuring SSH for key-only authentication..." +echo "" +echo "=== Step 4: Configure SSH for key-only authentication ===" SSHD_CONFIG="/etc/ssh/sshd_config" sed -i 's/^#*PasswordAuthentication.*/PasswordAuthentication no/' "$SSHD_CONFIG" sed -i 's/^#*PubkeyAuthentication.*/PubkeyAuthentication yes/' "$SSHD_CONFIG" sed -i 's/^#*PermitRootLogin.*/PermitRootLogin no/' "$SSHD_CONFIG" echo "SSH configured: key-only auth, root login disabled." -echo "[5/6] Configuring sudo for passwordless access..." +echo "" +echo "=== Step 5: Configure sudo for passwordless access ===" SUDOERS_FILE="/etc/sudoers.d/$USERNAME" echo "$USERNAME ALL=(ALL) NOPASSWD: ALL" > "$SUDOERS_FILE" chmod 0440 "$SUDOERS_FILE" echo "Sudo configured: $USERNAME can run sudo without password." -echo "[6/6] Enabling and starting sshd..." +echo "" +echo "=== Step 6: Enable and start sshd ===" systemctl enable sshd systemctl restart sshd +sleep 1 + +echo "" +echo "=== Step 7: Verify sshd is running ===" if systemctl is-active --quiet sshd; then - echo "sshd is running." + echo "SUCCESS: sshd is running." + echo "Status:" + systemctl status sshd --no-pager | head -5 else - echo "WARNING: sshd may not have started correctly. Check with: systemctl status sshd" + echo "ERROR: sshd is not running." + echo "Debug info:" + systemctl status sshd --no-pager + journalctl -u sshd -n 10 --no-pager + exit 1 fi echo "" @@ -72,8 +140,14 @@ echo "" echo "2. Connect from remote:" echo " ssh -p 2222 $USERNAME@" echo "" -echo " (Requires host-side port forwarding - see docs/kugetsu-setup.md)" -echo "" echo "3. Verify SSH access:" echo " ssh -p 2222 $USERNAME@ sudo systemctl status sshd" +echo "" +echo "=== Troubleshooting ===" +echo "" +echo "If SSH connection fails:" +echo " - Check sshd is running: systemctl status sshd" +echo " - Check sshd logs: journalctl -u sshd -n 20" +echo " - Verify user exists: id $USERNAME" +echo " - Verify SSH key was added: cat /home/$USERNAME/.ssh/authorized_keys" echo "" \ No newline at end of file