Windows equivalent for ‘ssh-copy-id’

If you’re someone who uses SSH frequently, you’ll be happy to know that Windows no longer requires using PuTTY. You can use SSH directly from the command line or PowerShell, just like on Linux or macOS.

To enable SSH public key authentication—whether for convenience or to enhance security—Windows does not include the ‘ssh-copy-id’ tool that Linux users often use. However, achieving the same functionality is straightforward.

Step 1: Generate an SSH key (if not already created)

Run the following command in PowerShell or Command Prompt:

ssh-keygen -t ed25519

This generates a key pair and places them by default in:

C:\Users\<YourUsername>\.ssh\id_ed25519

C:\Users\<YourUsername>\.ssh\id_ed25519.pub

If you’re prompted for a file location, press Enter to accept the default or specify a custom path.

Step 2: Copy the public key to the remote server

Use the following PowerShell commands to copy your public key to the remote server:

$pubkey = Get-Content "$HOME\.ssh\id_ed25519.pub"

ssh username@hostname "echo $pubkey >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"

Replace ‘username’ with your SSH user name and ‘hostname’ with the remote server’s address (IP or hostname).

Step 3: Test key-based authentication

Once the key is on the remote server, test the connection to ensure it works:

ssh username@hostname

If successful, you’ll be logged in without being prompted for a password.

Additional notes

Key location: By default, Windows SSH stores keys in ‘C:\Users\<YourUsername>\.ssh\’. Ensure that you reference the correct file if you’ve specified a non-default location during key generation.

Key type: The example uses ‘ed25519’, a modern and secure algorithm. If needed, you can use ‘rsa’ instead:

ssh-keygen -t rsa -b 4096

Enjoy seamless and secure SSH access!

Back