#!/bin/bash

# Check if correct number of arguments is provided
if [ "$#" -ne 2 ]; then
    echo "Usage: $0 <start_vmid> <end_vmid>"
    exit 1
fi

start_vmid=$1
end_vmid=$2

for (( vmid=start_vmid; vmid<=end_vmid; vmid++ )); do
    echo "Disabling SSH in container $vmid..."
    
    # Stop SSH service inside the container
    pct exec $vmid -- systemctl stop ssh
    pct exec $vmid -- systemctl stop sshd
    
    # Kill any running SSH processes
    pct exec $vmid -- pkill -9 sshd
    
    # Disable SSH from starting on boot
    pct exec $vmid -- systemctl disable ssh
    pct exec $vmid -- systemctl disable sshd
    
    # Mask SSH service to prevent manual start
    pct exec $vmid -- systemctl mask ssh
    pct exec $vmid -- systemctl mask sshd
    
    # Remove execution permissions from SSH binary
    pct exec $vmid -- chmod -x /usr/sbin/sshd
    
    echo "SSH and SSHD fully disabled in container $vmid."
done

echo "SSH and SSHD have been completely disabled in all specified LXC containers."
