Skip to content

Instantly share code, notes, and snippets.

@pirafrank
Created February 7, 2021 10:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pirafrank/883679626b42926bfc16aa7acc2b7fab to your computer and use it in GitHub Desktop.
Save pirafrank/883679626b42926bfc16aa7acc2b7fab to your computer and use it in GitHub Desktop.
ssh-copy-id as Windows PowerShell script. Put it in a folder in your PATH
function print($str) {
Write-Host "$str"
}
if ( $($args.Count) -ne 2 -And $($args.Count) -ne 3 ) {
$scriptName = $MyInvocation.MyCommand.Name
print("Usage: .\$scriptName [args...] pubKeyFile user@host")
exit
}
$sshargs=""
$sshPubKey=$args[0]
$remoteHost=$args[1]
if ( $($args.Count) -eq 3 ) {
$sshargs=$args[0]
$sshPubKey=$args[1]
$remoteHost=$args[2]
}
type $env:USERPROFILE\.ssh\$sshPubKey | ssh "$sshargs" "$remoteHost" "cat >> .ssh/authorized_keys"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment