9/11/2026
ssh-root
cd /Users/chaos/project/junma
./setup_cpa_ssh_key.sh 1.2.3.4#!/usr/bin/env bash
# One-time setup: install this Mac's public SSH key on a CPA server.
# Usage: ./setup_cpa_ssh_key.sh [host]
set -euo pipefail
TARGET_HOST="${1:-43.133.161.188}"
KEY_FILE="${SSH_KEY_PATH:-$HOME/.ssh/id_ed25519}"
mkdir -p "$HOME/.ssh"
chmod 700 "$HOME/.ssh"
if [[ ! -f "$KEY_FILE" ]]; then
ssh-keygen -t ed25519 -f "$KEY_FILE" -N "" -C "cpa-admin-${USER}@$(hostname -s)"
fi
echo "Enter the remote root password once when prompted."
ssh -o StrictHostKeyChecking=accept-new "root@${TARGET_HOST}" \
'umask 077; mkdir -p ~/.ssh; key=$(cat); touch ~/.ssh/authorized_keys; grep -qxF "$key" ~/.ssh/authorized_keys || printf "%s\n" "$key" >> ~/.ssh/authorized_keys' \
< "${KEY_FILE}.pub"
echo "Verifying passwordless login..."
ssh -o BatchMode=yes "root@${TARGET_HOST}" 'printf "SSH key login ready on %s\\n" "$(hostname)"'
Set-ExecutionPolicy -Scope Process Bypass
.\setup_cpa_ssh_key.ps1
.\setup_cpa_ssh_key.ps1 -HostName 43.133.161.188 -Port 22<#
.SYNOPSIS
Installs this Windows PC's SSH public key on a CPA server.
.EXAMPLE
.\setup_cpa_ssh_key.ps1
.\setup_cpa_ssh_key.ps1 -HostName 43.133.161.188 -Port 22
#>
[CmdletBinding()]
param(
[string]$HostName = "43.133.161.188",
[int]$Port = 22,
[string]$KeyPath = (Join-Path $env:USERPROFILE ".ssh\id_ed25519")
)
$ErrorActionPreference = "Stop"
foreach ($command in @("ssh", "ssh-keygen")) {
if (-not (Get-Command $command -ErrorAction SilentlyContinue)) {
throw "OpenSSH '$command' was not found. Install the Windows OpenSSH Client optional feature, then run this script again."
}
}
$sshDirectory = Split-Path -Parent $KeyPath
New-Item -ItemType Directory -Force -Path $sshDirectory | Out-Null
if (-not (Test-Path -LiteralPath $KeyPath)) {
$comment = "cpa-admin-$env:USERNAME@$env:COMPUTERNAME"
& ssh-keygen -t ed25519 -f $KeyPath -N "" -C $comment
if ($LASTEXITCODE -ne 0) { throw "Unable to create the SSH key." }
}
$publicKey = (Get-Content -Raw -LiteralPath "${KeyPath}.pub").Trim()
$encodedKey = [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes($publicKey))
$remoteInstall = "umask 077; mkdir -p ~/.ssh; key=`$(printf '%s' '$encodedKey' | base64 -d); touch ~/.ssh/authorized_keys; grep -qxF `"`$key`" ~/.ssh/authorized_keys || printf '%s\n' `"`$key`" >> ~/.ssh/authorized_keys"
Write-Host "Enter the remote root password once when prompted." -ForegroundColor Yellow
& ssh -o StrictHostKeyChecking=accept-new -p $Port "root@$HostName" $remoteInstall
if ($LASTEXITCODE -ne 0) { throw "The public key could not be installed." }
Write-Host "Verifying passwordless login..." -ForegroundColor Cyan
& ssh -o BatchMode=yes -p $Port "root@$HostName" 'printf "SSH key login ready on %s\n" "$(hostname)"'
if ($LASTEXITCODE -ne 0) { throw "Key installation completed, but passwordless login verification failed." }
Write-Host "Passwordless SSH is ready." -ForegroundColor Green