3

I want to copy public keys to my server from a windows system. And the problem I have is, that I don't get the path to the key. I've tried things like:

ssh-copy-id -i C:/Users/username/.ssh/mykey.pub user@serverIP

ssh-copy-id -i ~/.ssh/mykey.pub user@serverIP

The result is always

No such file or directory

What am I doing wrong? I'm using Git Bash for this on Windows 10

Patrick Münster
  • 459
  • 2
  • 5
  • 17

1 Answers1

8

Git's ssh is a version of OpenSSH. You can confirm it by running ssh -V under path\to\git\usr\bin. Here is what it evals on my machine:

OpenSSH_7.7p1, OpenSSL 1.0.2o  27 Mar 2018

ssh-copy-id script internally executes some *nix shell command (like exec, cat, etc. You can find more by opening the one under path\to\git\usr\bin in text mode), so it works only against *nix machines. That's the reason why ssh-copy-id under path\to\git\usr\bin is not a executable file.

According to this issue of PowerShell/Win32-OpenSSH, ssh-copy-id is not supported on Windows.

However, there are some alternative ways to do the same thing:

A powershell version of this answer can be

Get-Content $env:USERPROFILE\.ssh\id_rsa.pub | ssh <user>@<hostname> "cat >> .ssh/authorized_keys"

There is also a python script to do the same thing: ssh-copy-id for Windows.

Ynjxsjmh
  • 28,441
  • 6
  • 34
  • 52