Skip to content

Instantly share code, notes, and snippets.

@conradakunga
Last active September 14, 2020 02:02
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save conradakunga/7a20df44075066f8a9053a5dc91af44f to your computer and use it in GitHub Desktop.
Save conradakunga/7a20df44075066f8a9053a5dc91af44f to your computer and use it in GitHub Desktop.
Copy SSH Key From Windows 10
function ssh-copy-id([string]$userAtMachine, [string]$port = 22) {
# Get the generated public key
$key = "$ENV:USERPROFILE" + "/.ssh/id_rsa.pub"
# Verify that it exists
if (!(Test-Path "$key")) {
# Alert user
Write-Error "ERROR: '$key' does not exist!"
}
else {
# Copy the public key across
& cat "$key" | ssh $userAtMachine -p $port "umask 077; test -d .ssh || mkdir .ssh ; cat >> .ssh/authorized_keys || exit 1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment