feat: Add AD2 WinRM automation and modernize sync infrastructure
Comprehensive infrastructure improvements for AD2 (Domain Controller) remote management and NAS sync system modernization. ## AD2 Remote Access Enhancements **WinRM Configuration:** - Enabled PowerShell Remoting (port 5985) with full logging - Configured TrustedHosts for LAN/VPN access (172.16.*, 192.168.*, 10.*) - Created read-only service account (ClaudeTools-ReadOnly) for safe automation - Set up transcript logging for all remote sessions - Deployed 6 automation scripts to C:\ClaudeTools\Scripts\ (AD user/computer reports, GPO status, replication health, log rotation) **SSH Access:** - Installed OpenSSH Server (v10.0p2) - Generated ED25519 key for passwordless authentication - Configured SSH key authentication for sysadmin account **Benefits:** - Efficient remote operations via persistent WinRM sessions (vs individual SSH commands) - Secure read-only access for queries (no admin rights needed) - Comprehensive audit trail of all remote operations ## Sync System Modernization (AD2 <-> NAS) **Replaced PuTTY with OpenSSH:** - Migrated from pscp.exe/plink.exe to native OpenSSH scp/ssh tools - Added verbose logging (-v flag) for detailed error diagnostics - Implemented auto host-key acceptance (StrictHostKeyChecking=accept-new) - Enhanced error logging to capture actual SCP failure reasons **Problem Solved:** - Original sync errors (738 failures) had no root cause details - PuTTY's batch mode silently failed without error messages - New OpenSSH implementation logs full error output to sync-from-nas.log **Scripts Created:** - setup-openssh-sync.ps1: SSH key generation and NAS configuration - check-openssh-client.ps1: Verify OpenSSH availability - restore-and-fix-sync.ps1: Update Sync-FromNAS.ps1 to use OpenSSH - investigate-sync-errors.ps1: Analyze sync failures with context - test-winrm.ps1: WinRM connection testing (admin + service accounts) - demo-ad2-automation.ps1: WinRM automation examples (AD stats, sync status) ## DOS Batch File Line Ending Fixes **Problem:** All DOS batch files had Unix (LF) line endings instead of DOS (CRLF), causing parsing errors on DOS 6.22 machines. **Fixed:** - Local: 13 batch files converted to CRLF - Remote (AD2): 492 batch files scanned, 10 converted to CRLF - Affected files: DEPLOY.BAT, NWTOC.BAT, CTONW.BAT, UPDATE.BAT, STAGE.BAT, CHECKUPD.BAT, REBOOT.BAT, and station-specific batch files **Scripts Created:** - check-dos-line-endings.ps1: Scan and detect LF vs CRLF - convert-to-dos.ps1: Bulk conversion to DOS format - fix-ad2-dos-files.ps1: Remote conversion via WinRM ## Credentials & Documentation Updates **credentials.md additions:** - Peaceful Spirit VPN configuration (L2TP/IPSec) - AD2 WinRM/SSH access details (both admin and service accounts) - SSH keys and known_hosts configuration - Complete WinRM connection examples **Files Modified:** - credentials.md: +91 lines (VPN, AD2 automation access) - CTONW.BAT, NWTOC.BAT, REBOOT.BAT, STAGE.BAT: Line ending fixes - Infrastructure configs: vpn-connect.bat, vpn-disconnect.bat (CRLF) ## Test Results **WinRM Automation (demo-ad2-automation.ps1):** - Retrieved 178 AD users (156 enabled, 22 disabled, 40 active) - Retrieved 67 AD computers (67 Windows, 6 servers, 53 active) - Checked Dataforth sync status (2,249 files pushed, 738 errors logged) - All operations completed in single remote session (efficient!) **Sync System:** - OpenSSH tools confirmed available on AD2 - Backup created: Sync-FromNAS.ps1.backup-20260119-140918 - Script updated with error logging and verbose output - Next sync run will reveal actual error causes ## Technical Decisions 1. **WinRM over SSH:** More efficient for PowerShell operations, better error handling, native Windows integration 2. **Service Account:** Follows least-privilege principle, safer for automated queries, easier audit trail 3. **OpenSSH over PuTTY:** Modern, maintained, native Windows tool, better error reporting, supports key authentication without external tools 4. **Verbose Logging:** Critical for debugging 738 sync errors - now we'll see actual SCP failure reasons (permissions, paths, network issues) ## Next Steps 1. Monitor next sync run (every 15 minutes) for detailed error messages 2. Analyze SCP error output to identify root cause of 738 failures 3. Implement SSH key authentication for NAS (passwordless) 4. Consider SFTP batch mode for more reliable transfers Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
101
check-openssh-client.ps1
Normal file
101
check-openssh-client.ps1
Normal file
@@ -0,0 +1,101 @@
|
||||
# Check if OpenSSH client is available on AD2
|
||||
$password = ConvertTo-SecureString "Paper123!@#" -AsPlainText -Force
|
||||
$cred = New-Object System.Management.Automation.PSCredential("INTRANET\sysadmin", $password)
|
||||
|
||||
Write-Host "=== Checking OpenSSH Client Availability ===" -ForegroundColor Cyan
|
||||
Write-Host ""
|
||||
|
||||
Invoke-Command -ComputerName 192.168.0.6 -Credential $cred -ScriptBlock {
|
||||
Write-Host "[1] OpenSSH Client Installation Status" -ForegroundColor Yellow
|
||||
Write-Host "=" * 80 -ForegroundColor Gray
|
||||
|
||||
# Check if OpenSSH client is installed
|
||||
$sshClient = Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH.Client*'
|
||||
|
||||
if ($sshClient) {
|
||||
Write-Host "OpenSSH Client:" -ForegroundColor White
|
||||
Write-Host " Name: $($sshClient.Name)" -ForegroundColor White
|
||||
Write-Host " State: $($sshClient.State)" -ForegroundColor $(if ($sshClient.State -eq 'Installed') { "Green" } else { "Yellow" })
|
||||
} else {
|
||||
Write-Host "OpenSSH Client capability not found" -ForegroundColor Red
|
||||
}
|
||||
Write-Host ""
|
||||
|
||||
Write-Host "[2] Available SSH Commands" -ForegroundColor Yellow
|
||||
Write-Host "=" * 80 -ForegroundColor Gray
|
||||
|
||||
# Check for ssh.exe
|
||||
$sshPath = Get-Command ssh.exe -ErrorAction SilentlyContinue
|
||||
if ($sshPath) {
|
||||
Write-Host "[OK] ssh.exe found: $($sshPath.Source)" -ForegroundColor Green
|
||||
$sshVersion = & ssh.exe -V 2>&1
|
||||
Write-Host " Version: $sshVersion" -ForegroundColor Gray
|
||||
} else {
|
||||
Write-Host "[MISSING] ssh.exe not found" -ForegroundColor Red
|
||||
}
|
||||
|
||||
# Check for scp.exe
|
||||
$scpPath = Get-Command scp.exe -ErrorAction SilentlyContinue
|
||||
if ($scpPath) {
|
||||
Write-Host "[OK] scp.exe found: $($scpPath.Source)" -ForegroundColor Green
|
||||
} else {
|
||||
Write-Host "[MISSING] scp.exe not found" -ForegroundColor Red
|
||||
}
|
||||
|
||||
# Check for sftp.exe
|
||||
$sftpPath = Get-Command sftp.exe -ErrorAction SilentlyContinue
|
||||
if ($sftpPath) {
|
||||
Write-Host "[OK] sftp.exe found: $($sftpPath.Source)" -ForegroundColor Green
|
||||
} else {
|
||||
Write-Host "[MISSING] sftp.exe not found" -ForegroundColor Red
|
||||
}
|
||||
Write-Host ""
|
||||
|
||||
Write-Host "[3] Current PuTTY Tools" -ForegroundColor Yellow
|
||||
Write-Host "=" * 80 -ForegroundColor Gray
|
||||
|
||||
# Check existing PuTTY tools
|
||||
$pscpPath = "C:\Program Files\PuTTY\pscp.exe"
|
||||
$plinkPath = "C:\Program Files\PuTTY\plink.exe"
|
||||
|
||||
if (Test-Path $pscpPath) {
|
||||
Write-Host "[CURRENT] pscp.exe: $pscpPath" -ForegroundColor Cyan
|
||||
$pscpVersion = & $pscpPath -V 2>&1 | Select-Object -First 1
|
||||
Write-Host " $pscpVersion" -ForegroundColor Gray
|
||||
}
|
||||
|
||||
if (Test-Path $plinkPath) {
|
||||
Write-Host "[CURRENT] plink.exe: $plinkPath" -ForegroundColor Cyan
|
||||
}
|
||||
Write-Host ""
|
||||
|
||||
Write-Host "[4] Test SCP Transfer (if available)" -ForegroundColor Yellow
|
||||
Write-Host "=" * 80 -ForegroundColor Gray
|
||||
|
||||
if ($scpPath) {
|
||||
# Create a test file
|
||||
$testFile = "C:\Shares\test\scripts\openssh-test.txt"
|
||||
"OpenSSH SCP Test - $(Get-Date)" | Out-File -FilePath $testFile -Encoding ASCII
|
||||
|
||||
Write-Host "Created test file: $testFile" -ForegroundColor White
|
||||
Write-Host "Ready to test SCP transfer to NAS" -ForegroundColor Green
|
||||
Write-Host ""
|
||||
Write-Host "Test command would be:" -ForegroundColor Yellow
|
||||
Write-Host " scp -v $testFile root@192.168.0.9:/data/test/scripts/" -ForegroundColor Gray
|
||||
Write-Host ""
|
||||
Write-Host "Benefits vs PuTTY pscp:" -ForegroundColor Cyan
|
||||
Write-Host " - Native error messages" -ForegroundColor White
|
||||
Write-Host " - SSH key support (no passwords in scripts)" -ForegroundColor White
|
||||
Write-Host " - Verbose logging with -v flag" -ForegroundColor White
|
||||
Write-Host " - Better batch mode handling" -ForegroundColor White
|
||||
Write-Host " - StrictHostKeyChecking=accept-new (auto-accept on first connect)" -ForegroundColor White
|
||||
} else {
|
||||
Write-Host "OpenSSH client not available - would need to install" -ForegroundColor Red
|
||||
Write-Host ""
|
||||
Write-Host "Install command:" -ForegroundColor Yellow
|
||||
Write-Host " Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0" -ForegroundColor Gray
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "=== Check Complete ===" -ForegroundColor Cyan
|
||||
Reference in New Issue
Block a user