Skip to content

Instantly share code, notes, and snippets.

@Postroggy
Last active March 4, 2026 08:49
Show Gist options
  • Select an option

  • Save Postroggy/84d8b5c70c4a1f1b9404bd745dbd85dc to your computer and use it in GitHub Desktop.

Select an option

Save Postroggy/84d8b5c70c4a1f1b9404bd745dbd85dc to your computer and use it in GitHub Desktop.
ssh-copy-id on windows

paste to terminal

function ssh-copy-id([string]$userAtMachine, $args){   
    $publicKey = "$ENV:USERPROFILE" + "/.ssh/id_rsa.pub"
    if (!(Test-Path "$publicKey")){
        Write-Error "ERROR: failed to open ID file '$publicKey': No such file"            
    }
    else {
        & cat "$publicKey" | ssh $args $userAtMachine "umask 077; test -d .ssh || mkdir .ssh ; cat >> .ssh/authorized_keys || exit 1"      
    }
}

run

ssh-copy-id {hostname}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment