211 lines
6.6 KiB
Bash
211 lines
6.6 KiB
Bash
|
|
#!/bin/bash
|
||
|
|
source ~/.bashrc
|
||
|
|
# Test SSH Access to Proxmox Servers
|
||
|
|
# Tests SSH connectivity to both ML110 and R630
|
||
|
|
|
||
|
|
set -e
|
||
|
|
|
||
|
|
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"
|
||
|
|
}
|
||
|
|
|
||
|
|
log_test() {
|
||
|
|
echo -e "${BLUE}[TEST]${NC} $1"
|
||
|
|
}
|
||
|
|
|
||
|
|
ML110_IP="${PROXMOX_ML110_IP:-192.168.1.206}"
|
||
|
|
R630_IP="${PROXMOX_R630_IP:-192.168.1.49}"
|
||
|
|
|
||
|
|
test_ssh() {
|
||
|
|
local host=$1
|
||
|
|
local name=$2
|
||
|
|
|
||
|
|
log_test "Testing SSH to $name ($host)..."
|
||
|
|
|
||
|
|
# Test network connectivity first
|
||
|
|
if ping -c 1 -W 2 "$host" &>/dev/null; then
|
||
|
|
echo -e " ${GREEN}✓${NC} Network reachable (ping)"
|
||
|
|
else
|
||
|
|
echo -e " ${YELLOW}⚠${NC} Ping failed (may be blocked by firewall)"
|
||
|
|
fi
|
||
|
|
|
||
|
|
# Test SSH port
|
||
|
|
if timeout 3 bash -c "cat < /dev/null > /dev/tcp/$host/22" 2>/dev/null; then
|
||
|
|
echo -e " ${GREEN}✓${NC} SSH port 22 is open"
|
||
|
|
else
|
||
|
|
echo -e " ${RED}✗${NC} SSH port 22 is closed or filtered"
|
||
|
|
return 1
|
||
|
|
fi
|
||
|
|
|
||
|
|
# Test SSH connection
|
||
|
|
log_test " Attempting SSH connection..."
|
||
|
|
if ssh -o StrictHostKeyChecking=no -o ConnectTimeout=5 -o BatchMode=yes "root@$host" "echo 'SSH connection successful'" 2>&1 | grep -q "SSH connection successful"; then
|
||
|
|
echo -e " ${GREEN}✓${NC} SSH connection successful"
|
||
|
|
|
||
|
|
# Test command execution
|
||
|
|
log_test " Testing command execution..."
|
||
|
|
local hostname=$(ssh -o StrictHostKeyChecking=no -o ConnectTimeout=5 "root@$host" "hostname" 2>/dev/null)
|
||
|
|
if [ -n "$hostname" ]; then
|
||
|
|
echo -e " ${GREEN}✓${NC} Command execution works"
|
||
|
|
echo -e " ${GREEN}✓${NC} Hostname: $hostname"
|
||
|
|
|
||
|
|
# Get system info
|
||
|
|
local uptime=$(ssh -o StrictHostKeyChecking=no -o ConnectTimeout=5 "root@$host" "uptime -p" 2>/dev/null || echo "unknown")
|
||
|
|
local os=$(ssh -o StrictHostKeyChecking=no -o ConnectTimeout=5 "root@$host" "cat /etc/os-release | grep PRETTY_NAME | cut -d'=' -f2 | tr -d '\"'" 2>/dev/null || echo "unknown")
|
||
|
|
echo -e " ${GREEN}✓${NC} Uptime: $uptime"
|
||
|
|
echo -e " ${GREEN}✓${NC} OS: $os"
|
||
|
|
|
||
|
|
return 0
|
||
|
|
else
|
||
|
|
echo -e " ${YELLOW}⚠${NC} SSH works but command execution failed"
|
||
|
|
return 1
|
||
|
|
fi
|
||
|
|
else
|
||
|
|
echo -e " ${RED}✗${NC} SSH connection failed"
|
||
|
|
echo -e " ${YELLOW}Possible reasons:${NC}"
|
||
|
|
echo -e " - SSH service not running"
|
||
|
|
echo -e " - Root login disabled"
|
||
|
|
echo -e " - Authentication failed (need SSH key or password)"
|
||
|
|
echo -e " - Firewall blocking connection"
|
||
|
|
return 1
|
||
|
|
fi
|
||
|
|
}
|
||
|
|
|
||
|
|
test_ssh_with_password() {
|
||
|
|
local host=$1
|
||
|
|
local name=$2
|
||
|
|
local password=$3
|
||
|
|
|
||
|
|
log_test "Testing SSH with password authentication to $name ($host)..."
|
||
|
|
|
||
|
|
# Check if sshpass is available
|
||
|
|
if ! command -v sshpass &> /dev/null; then
|
||
|
|
log_warn "sshpass not installed - cannot test password authentication"
|
||
|
|
log_info "Install with: sudo apt install sshpass"
|
||
|
|
return 1
|
||
|
|
fi
|
||
|
|
|
||
|
|
if sshpass -p "$password" ssh -o StrictHostKeyChecking=no -o ConnectTimeout=5 "root@$host" "echo 'SSH with password successful'" 2>&1 | grep -q "SSH with password successful"; then
|
||
|
|
echo -e " ${GREEN}✓${NC} SSH with password authentication works"
|
||
|
|
return 0
|
||
|
|
else
|
||
|
|
echo -e " ${RED}✗${NC} SSH with password authentication failed"
|
||
|
|
return 1
|
||
|
|
fi
|
||
|
|
}
|
||
|
|
|
||
|
|
main() {
|
||
|
|
echo "========================================="
|
||
|
|
echo "SSH Access Test - Proxmox Servers"
|
||
|
|
echo "========================================="
|
||
|
|
echo ""
|
||
|
|
|
||
|
|
local ml110_ok=false
|
||
|
|
local r630_ok=false
|
||
|
|
|
||
|
|
# Test ML110
|
||
|
|
log_info "Testing ML110 (HPE ML110 Gen9)..."
|
||
|
|
if test_ssh "$ML110_IP" "ML110"; then
|
||
|
|
ml110_ok=true
|
||
|
|
log_info "✓ ML110 SSH access: WORKING"
|
||
|
|
else
|
||
|
|
log_error "✗ ML110 SSH access: FAILED"
|
||
|
|
|
||
|
|
# Try with password if available
|
||
|
|
if [ -n "${PVE_ROOT_PASS:-}" ]; then
|
||
|
|
log_info "Attempting password authentication..."
|
||
|
|
if test_ssh_with_password "$ML110_IP" "ML110" "$PVE_ROOT_PASS"; then
|
||
|
|
ml110_ok=true
|
||
|
|
log_info "✓ ML110 SSH with password: WORKING"
|
||
|
|
fi
|
||
|
|
fi
|
||
|
|
fi
|
||
|
|
|
||
|
|
echo ""
|
||
|
|
echo "----------------------------------------"
|
||
|
|
echo ""
|
||
|
|
|
||
|
|
# Test R630
|
||
|
|
log_info "Testing R630 (Dell R630)..."
|
||
|
|
if test_ssh "$R630_IP" "R630"; then
|
||
|
|
r630_ok=true
|
||
|
|
log_info "✓ R630 SSH access: WORKING"
|
||
|
|
else
|
||
|
|
log_error "✗ R630 SSH access: FAILED"
|
||
|
|
|
||
|
|
# Try with password if available
|
||
|
|
if [ -n "${PVE_ROOT_PASS:-}" ]; then
|
||
|
|
log_info "Attempting password authentication..."
|
||
|
|
if test_ssh_with_password "$R630_IP" "R630" "$PVE_ROOT_PASS"; then
|
||
|
|
r630_ok=true
|
||
|
|
log_info "✓ R630 SSH with password: WORKING"
|
||
|
|
fi
|
||
|
|
fi
|
||
|
|
fi
|
||
|
|
|
||
|
|
echo ""
|
||
|
|
echo "========================================="
|
||
|
|
echo "Summary"
|
||
|
|
echo "========================================="
|
||
|
|
echo ""
|
||
|
|
|
||
|
|
if [ "$ml110_ok" = true ]; then
|
||
|
|
log_info "ML110 ($ML110_IP): ✓ SSH ACCESSIBLE"
|
||
|
|
else
|
||
|
|
log_error "ML110 ($ML110_IP): ✗ SSH NOT ACCESSIBLE"
|
||
|
|
log_warn " - Enable SSH: systemctl enable ssh && systemctl start ssh"
|
||
|
|
log_warn " - Allow root login: Edit /etc/ssh/sshd_config (PermitRootLogin yes)"
|
||
|
|
log_warn " - Check firewall: iptables -L"
|
||
|
|
fi
|
||
|
|
|
||
|
|
if [ "$r630_ok" = true ]; then
|
||
|
|
log_info "R630 ($R630_IP): ✓ SSH ACCESSIBLE"
|
||
|
|
else
|
||
|
|
log_error "R630 ($R630_IP): ✗ SSH NOT ACCESSIBLE"
|
||
|
|
log_warn " - Enable SSH: systemctl enable ssh && systemctl start ssh"
|
||
|
|
log_warn " - Allow root login: Edit /etc/ssh/sshd_config (PermitRootLogin yes)"
|
||
|
|
log_warn " - Check firewall: iptables -L"
|
||
|
|
fi
|
||
|
|
|
||
|
|
echo ""
|
||
|
|
|
||
|
|
if [ "$ml110_ok" = true ] && [ "$r630_ok" = true ]; then
|
||
|
|
log_info "✓ Both servers have SSH access - ready for template recreation!"
|
||
|
|
return 0
|
||
|
|
elif [ "$ml110_ok" = true ]; then
|
||
|
|
log_warn "Only ML110 has SSH access - can proceed with template recreation"
|
||
|
|
return 0
|
||
|
|
else
|
||
|
|
log_error "No SSH access available - need to enable SSH first"
|
||
|
|
return 1
|
||
|
|
fi
|
||
|
|
}
|
||
|
|
|
||
|
|
main "$@"
|
||
|
|
|