Blog: Copy SSH Key From Windows to Any System

A dead-simple guide to copying your public SSH key to any new system (Windows, Linux, or macOS).

Hello - long time no see!

As stated in the preface of this article, this is a super-simple guide to copying your public SSH key to a new system.

It would be even easier with ssh-copy-id, but Windows doesn't include that tool by default. However, that doesn't mean it needs to be difficult.

The Steps

Before you begin, ensure you have your public key at hand (usually located at %USERPROFILE%\.ssh\id_rsa.pub) - it just needs to exist.

Now you have two options: copy to a system you've previously used for SSH, or copy to a fresh system (EG: a brand-spanking-new Arch Linux installation). If you've previously used the target system for SSH, your authorized_keys file will already exist, so use option A. If not, it likely won't, so use option B.

Option A - Pre-existing authorized_keys

Simply open up a Powershell window and enter this command: type $env:USERPROFILE\.ssh\id_rsa.pub | ssh <target-IP> -l <username> "cat >> .ssh/authorized_keys" (replacing <target-IP> with the IP address or domain of your target system, and <username> with your target username - if your username is the same on both systems, you can remove -l).

Option B - New System

This command is similar to the one used in Option A, but automatically creates the necessary authorized_keys file for you. Open up a Powershell window and enter this command: type $env:USERPROFILE\.ssh\id_rsa.pub | ssh <target-IP> -l <username> "mkdir .ssh && touch .ssh/authorized_keys && cat >> .ssh/authorized_keys" (replacing <target-IP> with the IP address or domain of your target system, and <username> with your target username - if your username is the same on both systems, you can remove -l).

Final Notes

The initial setup method was nabbed from Chris J Hart's blog. I expanded upon his super-helpful information, adding setup instructions for a new system. Go show his post some love and tell us both if we helped you out!