Initial commit: loc_az_hci (smom-dbis-138 excluded via .gitignore)
Some checks failed
Test / test (push) Has been cancelled
Some checks failed
Test / test (push) Has been cancelled
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
109
scripts/infrastructure/enable-ssh-r630.sh
Executable file
109
scripts/infrastructure/enable-ssh-r630.sh
Executable file
@@ -0,0 +1,109 @@
|
||||
#!/bin/bash
|
||||
source ~/.bashrc
|
||||
# Enable SSH on R630 Proxmox Host (192.168.1.49)
|
||||
# This script attempts to enable SSH via Proxmox API
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
|
||||
|
||||
# Load environment variables
|
||||
if [ -f "$PROJECT_ROOT/.env" ]; then
|
||||
set -a
|
||||
source <(grep -v '^#' "$PROJECT_ROOT/.env" | grep -v '^$' | sed 's/#.*$//' | grep '=')
|
||||
set +a
|
||||
fi
|
||||
|
||||
# Colors
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m'
|
||||
|
||||
log_info() { echo -e "${GREEN}[INFO]${NC} $1"; }
|
||||
log_warn() { echo -e "${YELLOW}[WARN]${NC} $1"; }
|
||||
log_error() { echo -e "${RED}[ERROR]${NC} $1"; }
|
||||
|
||||
PROXMOX_URL="${PROXMOX_R630_URL:-https://192.168.1.49:8006}"
|
||||
PROXMOX_USER="${PVE_USERNAME:-root@pam}"
|
||||
PROXMOX_PASS="${PVE_ROOT_PASS:-}"
|
||||
PROXMOX_NODE="${PROXMOX_R630_NODE:-pve}"
|
||||
|
||||
if [ -z "$PROXMOX_PASS" ]; then
|
||||
log_error "PVE_ROOT_PASS not set in .env file"
|
||||
log_info "Please set PVE_ROOT_PASS in .env or provide password:"
|
||||
read -sp "Password: " PROXMOX_PASS
|
||||
echo ""
|
||||
fi
|
||||
|
||||
log_info "Attempting to enable SSH on R630 (192.168.1.49) via Proxmox API..."
|
||||
|
||||
# Get API token
|
||||
log_info "Authenticating with Proxmox API..."
|
||||
RESPONSE=$(curl -s -k --connect-timeout 10 --max-time 15 \
|
||||
-d "username=${PROXMOX_USER}&password=${PROXMOX_PASS}" \
|
||||
"${PROXMOX_URL}/api2/json/access/ticket" 2>&1)
|
||||
|
||||
if ! echo "$RESPONSE" | grep -q '"data"'; then
|
||||
log_error "Failed to authenticate with Proxmox API"
|
||||
log_warn "Response: $RESPONSE"
|
||||
log_info ""
|
||||
log_info "Alternative: Enable SSH via Proxmox Web UI:"
|
||||
log_info " 1. Open ${PROXMOX_URL} in browser"
|
||||
log_info " 2. Login as root"
|
||||
log_info " 3. Go to: System → Services → ssh"
|
||||
log_info " 4. Click 'Enable' and 'Start'"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
TICKET=$(echo "$RESPONSE" | grep -o '"ticket":"[^"]*' | cut -d'"' -f4)
|
||||
CSRF=$(echo "$RESPONSE" | grep -o '"CSRFPreventionToken":"[^"]*' | cut -d'"' -f4)
|
||||
|
||||
if [ -z "$TICKET" ] || [ -z "$CSRF" ]; then
|
||||
log_error "Failed to get API token"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
log_info "✓ Authenticated successfully"
|
||||
|
||||
# Enable SSH service
|
||||
log_info "Enabling SSH service..."
|
||||
SSH_RESPONSE=$(curl -s -k -X POST \
|
||||
-H "Cookie: PVEAuthCookie=${TICKET}" \
|
||||
-H "CSRFPreventionToken: ${CSRF}" \
|
||||
"${PROXMOX_URL}/api2/json/nodes/${PROXMOX_NODE}/services/ssh/start" 2>&1)
|
||||
|
||||
if echo "$SSH_RESPONSE" | grep -q '"data"'; then
|
||||
log_info "✓ SSH service started"
|
||||
else
|
||||
log_warn "SSH service start response: $SSH_RESPONSE"
|
||||
fi
|
||||
|
||||
# Enable SSH on boot
|
||||
log_info "Enabling SSH on boot..."
|
||||
ENABLE_RESPONSE=$(curl -s -k -X POST \
|
||||
-H "Cookie: PVEAuthCookie=${TICKET}" \
|
||||
-H "CSRFPreventionToken: ${CSRF}" \
|
||||
-d "enable=1" \
|
||||
"${PROXMOX_URL}/api2/json/nodes/${PROXMOX_NODE}/services/ssh" 2>&1)
|
||||
|
||||
if echo "$ENABLE_RESPONSE" | grep -q '"data"'; then
|
||||
log_info "✓ SSH service enabled on boot"
|
||||
else
|
||||
log_warn "SSH enable response: $ENABLE_RESPONSE"
|
||||
fi
|
||||
|
||||
# Test SSH access
|
||||
log_info "Testing SSH access..."
|
||||
sleep 2
|
||||
if ssh -i "${SSH_KEY:-$HOME/.ssh/id_ed25519_proxmox}" -o StrictHostKeyChecking=no -o ConnectTimeout=5 "root@192.168.1.49" "echo 'SSH OK'" &>/dev/null; then
|
||||
log_info "✓ SSH access confirmed!"
|
||||
log_info "You can now SSH to R630:"
|
||||
log_info " ssh -i ~/.ssh/id_ed25519_proxmox root@192.168.1.49"
|
||||
else
|
||||
log_warn "SSH test failed. SSH may need a moment to start."
|
||||
log_info "Try manually: ssh root@192.168.1.49"
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user