Skip to content

PowerShell - Copying SSH Keys to Remote HostsΒΆ

Given Windows does not include the ssh-copy-id binary, there are effectively three methods available to copy SSH keys:

  1. Copy the key to a Linux/macOS host and run ssh-copy-id from there
  2. Copy/paste the public key to ~/.ssh/authorized_hosts which can be unreliable at times - but does work
  3. Use the Get-Content PowerShell cmdlet to perform the equivalent of ssh-copy-id:
Get-Content "$env:USERPROFILE\.ssh\id_rsa.pub" | ssh username@remote_host "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"