Files
nas_connection/deploy/register-ssh-key.ps1
2026-06-08 22:19:08 +09:00

32 lines
878 B
PowerShell

param(
[string]$NasUser = "y2keui",
[string]$NasHost = "comtropy.synology.me",
[int]$NasPort = 50022,
[string]$SshKeyPath = "$env:USERPROFILE\.ssh\nas_codex_ed25519"
)
$ErrorActionPreference = "Stop"
$publicKeyPath = "$SshKeyPath.pub"
if (-not (Test-Path $publicKeyPath)) {
Write-Host "Missing public key: $publicKeyPath" -ForegroundColor Yellow
exit 1
}
$remote = "${NasUser}@${NasHost}"
$remoteCommand = @'
export PATH=/usr/local/bin:/var/packages/ContainerManager/target/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin
umask 077
mkdir -p ~/.ssh
cat >> ~/.ssh/authorized_keys
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
'@
Get-Content -Raw $publicKeyPath | ssh -p $NasPort $remote $remoteCommand
if ($LASTEXITCODE -ne 0) {
throw "Registering SSH public key failed with exit code $LASTEXITCODE"
}
Write-Host "Public key registered: $publicKeyPath"