Polar-Labs

Menu

©

PowerShell: No ssh-copy-id? No Problem.

If ssh-copy-id isn’t available on Windows, you can still copy your SSH key to a remote server using a single PowerShell command. Here’s how to do it with and without permission fixes, all from PowerShell.

To avoid any SSH permission issues, it’s a good idea to set permissions explicitly — especially on fresh servers or new user accounts:

PowerShell
type $env:USERPROFILE\.ssh\id_rsa.pub | ssh username@remote-server "mkdir -p ~/.ssh; cat >> ~/.ssh/authorized_keys; chmod 700 ~/.ssh; chmod 600 ~/.ssh/authorized_keys"

What this does:

  • Ensures the .ssh directory exists
  • Appends your public key (doesn’t overwrite anything)
  • Sets secure permissions (700 for the folder, 600 for the file) — required by SSH to accept the key

If you’re confident the remote server already has the proper .ssh directory and permissions, use this simple one-liner:

PowerShell
type $env:USERPROFILE\.ssh\id_rsa.pub | ssh username@remote-server "cat >> ~/.ssh/authorized_keys"