Skip to content

Instantly share code, notes, and snippets.

@elico
Last active February 22, 2026 17:45
Show Gist options
  • Select an option

  • Save elico/6403ab1a5df4c8ca0eadfcc8d9de81d9 to your computer and use it in GitHub Desktop.

Select an option

Save elico/6403ab1a5df4c8ca0eadfcc8d9de81d9 to your computer and use it in GitHub Desktop.
$FunctionCode = @'
function ssh-copy-id {
param([Parameter(Mandatory=$true)][string]$RemoteTarget)
$KeyPath = "$env:USERPROFILE\.ssh\id_ed25519.pub"
if (!(Test-Path $KeyPath)) {
Write-Error "Public key not found at $KeyPath"
return
}
$PubKey = Get-Content $KeyPath
ssh $RemoteTarget "mkdir -p ~/.ssh && chmod 700 ~/.ssh && echo '$PubKey' >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"
}
'@
Add-Content -Path $PROFILE -Value $FunctionCode
. $PROFILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment