feat(sshd-setup): multi-distro support and verification steps

- sshd-setup.sh: Auto-detect OS (Debian/Ubuntu/Fedora/RHEL/CentOS)
- Use appropriate package manager (apt-get vs dnf)
- Add verification steps after each major phase
- Exit with error if sshd installation fails
- Exit with error if sshd doesn't start successfully
- Add troubleshooting section in output

- kugetsu-install.sh: Add verification that kugetsu binary exists

- kugetsu-setup.md: Document multi-distro installation commands
This commit is contained in:
shokollm
2026-03-30 04:27:23 +00:00
parent 4da4d46bd1
commit 3c92a12f28
3 changed files with 121 additions and 15 deletions

View File

@@ -26,16 +26,23 @@ This guide covers setting up a server/container with kugetsu for remote agent in
### Incus ### Incus
```bash ```bash
# Create container # Create container (Debian/Ubuntu)
incus launch images:debian/12 <container-name> incus launch images:debian/12 <container-name>
# Or create Fedora container
incus launch images:fedora/43 <container-name>
# Or use an existing container # Or use an existing container
incus exec <container-name> -- bash incus exec <container-name> -- bash
# Ensure systemd is installed (Debian/Ubuntu) # Ensure systemd is installed
# For Debian/Ubuntu:
incus exec <container-name> -- apt-get update incus exec <container-name> -- apt-get update
incus exec <container-name> -- apt-get install -y systemd incus exec <container-name> -- apt-get install -y systemd
# For Fedora:
incus exec <container-name> -- dnf install -y systemd
# Enable systemd in container (Incus specific - verify with your setup) # Enable systemd in container (Incus specific - verify with your setup)
incus config set <container-name> security.syscalls.intercept.systemd true incus config set <container-name> security.syscalls.intercept.systemd true
@@ -57,16 +64,33 @@ bash skills/kugetsu/scripts/sshd-setup.sh <username>
Replace `<username>` with your preferred username, or omit to use default `kugetsu`. Replace `<username>` 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 ### Manual Setup
If you prefer to set up SSH manually: If you prefer to set up SSH manually:
#### 1. Install openssh-server #### 1. Install openssh-server
**Debian/Ubuntu:**
```bash ```bash
apt-get update && apt-get install -y openssh-server sudo 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 #### 2. Create non-root user
```bash ```bash

View File

@@ -38,6 +38,14 @@ add_to_shell "$HOME/.bashrc"
add_to_shell "$HOME/.zshrc" add_to_shell "$HOME/.zshrc"
echo "" 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 "Installation complete!"
echo "" echo ""
echo "Run this to start using kugetsu immediately:" echo "Run this to start using kugetsu immediately:"

View File

@@ -7,12 +7,44 @@ echo "=== kugetsu SSH Setup ==="
echo "Target user: $USERNAME" echo "Target user: $USERNAME"
echo "" 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 if ! command -v systemctl &> /dev/null; then
echo "ERROR: systemd not found." echo "ERROR: systemd not found."
echo "" echo ""
echo "This script requires systemd to be installed and running inside the container." echo "This script requires systemd to be installed and running inside the container."
echo "Please install systemd first:" echo "Please install systemd first:"
case "$OS_TYPE" in
debian)
echo " apt-get update && apt-get install -y systemd" 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 ""
echo "If you are running in a container that doesn't support systemd, consider:" echo "If you are running in a container that doesn't support systemd, consider:"
echo " - Using a container image with systemd support" echo " - Using a container image with systemd support"
@@ -20,13 +52,36 @@ if ! command -v systemctl &> /dev/null; then
exit 1 exit 1
fi fi
echo "[1/6] Updating package lists..." echo ""
apt-get update -qq 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..." echo ""
apt-get install -y -qq openssh-server sudo 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 if ! id "$USERNAME" &> /dev/null; then
useradd -m -s /bin/bash "$USERNAME" useradd -m -s /bin/bash "$USERNAME"
echo "User '$USERNAME' created." echo "User '$USERNAME' created."
@@ -34,27 +89,40 @@ else
echo "User '$USERNAME' already exists." echo "User '$USERNAME' already exists."
fi 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" SSHD_CONFIG="/etc/ssh/sshd_config"
sed -i 's/^#*PasswordAuthentication.*/PasswordAuthentication no/' "$SSHD_CONFIG" sed -i 's/^#*PasswordAuthentication.*/PasswordAuthentication no/' "$SSHD_CONFIG"
sed -i 's/^#*PubkeyAuthentication.*/PubkeyAuthentication yes/' "$SSHD_CONFIG" sed -i 's/^#*PubkeyAuthentication.*/PubkeyAuthentication yes/' "$SSHD_CONFIG"
sed -i 's/^#*PermitRootLogin.*/PermitRootLogin no/' "$SSHD_CONFIG" sed -i 's/^#*PermitRootLogin.*/PermitRootLogin no/' "$SSHD_CONFIG"
echo "SSH configured: key-only auth, root login disabled." 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" SUDOERS_FILE="/etc/sudoers.d/$USERNAME"
echo "$USERNAME ALL=(ALL) NOPASSWD: ALL" > "$SUDOERS_FILE" echo "$USERNAME ALL=(ALL) NOPASSWD: ALL" > "$SUDOERS_FILE"
chmod 0440 "$SUDOERS_FILE" chmod 0440 "$SUDOERS_FILE"
echo "Sudo configured: $USERNAME can run sudo without password." 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 enable sshd
systemctl restart sshd systemctl restart sshd
sleep 1
echo ""
echo "=== Step 7: Verify sshd is running ==="
if systemctl is-active --quiet sshd; then 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 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 fi
echo "" echo ""
@@ -72,8 +140,14 @@ echo ""
echo "2. Connect from remote:" echo "2. Connect from remote:"
echo " ssh -p 2222 $USERNAME@<container-host-ip>" echo " ssh -p 2222 $USERNAME@<container-host-ip>"
echo "" echo ""
echo " (Requires host-side port forwarding - see docs/kugetsu-setup.md)"
echo ""
echo "3. Verify SSH access:" echo "3. Verify SSH access:"
echo " ssh -p 2222 $USERNAME@<container-host-ip> sudo systemctl status sshd" echo " ssh -p 2222 $USERNAME@<container-host-ip> sudo systemctl status sshd"
echo "" 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 ""