1

I want to copy an SSH public key to a remote device on Windows. I'm not using PuTTYgen rather just OpenSSH through PowerShell. I ran

ssh-keygen -t rsa

And it gave me a public and private key in my .ssh folder but if I try to do

ssh-copy-id -i ~/.ssh/id_rsa.pub <name@machine>

I get the same error:

ssh-copy-id : The term 'ssh-copy-id' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

Perhaps the ssh-copy-id command was meant for Linux, but I was able to get some other commands meant for Linux to run.

How do I copy the key from my Windows laptop to my remote machine? Is it even possible to do just in Windows without an app like PuTTYgen?

squillman
  • 7,341
  • 3
  • 37
  • 42
magnetosticker
  • 119
  • 1
  • 4
  • 2
    Have a look at this https://serverfault.com/questions/224810/is-there-an-equivalent-to-ssh-copy-id-for-windows – squillman Oct 14 '22 at 17:19

2 Answers2

1

All you are actually doing is adding the contents of your id_rsa.pub file to your ~/.ssh/authorized_keys file on your linux host. (You may need to run 'systemctl restart ssh'.)

On your windows machine you then use the -i parameter:

ssh -i {path to private key file}\id_rsa {name}@{machine}

If you used a passphrase you will be prompted for that, otherwise it will let you right in.

Benj Sanders
  • 111
  • 4
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 24 '23 at 22:03
1

I've got cygwin installed, and that has ssh and includes ssh-copy-id (which is a script btw).

$ which ssh-copy-id
/usr/bin/ssh-copy-id

By the way if you get an error like what you got then a basic troubleshooting step to simplify is just to try $ ssh-copy-id <ENTER> so as you know it's nothing to do with all the parameters you put after ssh-copy-id.

This article mentions the manual method of ssh-copy-id https://chrisjhart.com/Windows-10-ssh-copy-id/

type $env:USERPROFILE\.ssh\id_rsa.pub | ssh {IP-ADDRESS-OR-FQDN} "cat >> .ssh/authorized_keys"

and he gives an example

PS C:\Users\Christopher> type $env:USERPROFILE\.ssh\id_rsa.pub | ssh 192.168.30.31 "cat >> .ssh/authorized_keys"

a bit more info, related To use ssh-id-copy do you need both id_rsa.pub and id_rsa?

barlop
  • 23,380
  • 43
  • 145
  • 225