GeoNetAgent, LDAPWeb, server-audit, server-connection
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

33 lines
1.3 KiB

# Setup SSH key — root@10.100.1.28 (Mailcow VM, Ubuntu)
# SSOT: server-audit/docs/guide/ssh-access.md
# Usage: .\Mailcow\scripts\setup-ssh-key-simple.ps1# Sekali jalan: minta password root 1x, lalu login key-only.
$ErrorActionPreference = 'Stop'
$hostIp = '10.100.1.28'
$key = Join-Path $env:USERPROFILE '.ssh\id_ed25519_mailcow'
$pub = "$key.pub"
if (-not (Test-Path $pub)) {
Write-Host "Generating key $key ..."
ssh-keygen -t ed25519 -f $key -C 'geonet-mailcow' -N '""'
}
Write-Host "Fixing private key ACL..."
icacls $key /inheritance:r 2>$null | Out-Null
icacls $key /grant:r "${env:USERNAME}:(R)" 2>$null | Out-Null
Write-Host "Upload public key ke root@${hostIp} (password 1x)..."
type $pub | ssh -o PreferredAuthentications=password -o PubkeyAuthentication=no "root@${hostIp}" -p 22 "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys && echo KEY_INSTALLED_OK"
Write-Host ""
Write-Host "Test key-only..."
ssh -i $key -o BatchMode=yes -o IdentitiesOnly=yes -o PreferredAuthentications=publickey "root@${hostIp}" -p 22 "echo KEY_AUTH_OK"
if ($LASTEXITCODE -ne 0) {
Write-Host ""
Write-Host "Masih gagal — cek auth log (password sekali):"
Write-Host " ssh root@${hostIp} -p 22 `"grep sshd /var/log/auth.log | tail -20`""
exit 1
}
Write-Host "Success. Login: ssh mailcow"