ssh-copy-id on windows doesn't work: No such file or directory
Asked Answered
N

2

6

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

Nappie answered 23/8, 2019 at 15:26 Comment(0)
P
14

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.

Poteat answered 22/8, 2020 at 5:38 Comment(0)
C
0

I assume you have OpenSSH installed on your local Ms. Windows machine

When installing OpenSSH, should include scp commands. just type scp on your command prompt to ensure this program is installed.

You could use this command:

  1. First change prompt to working directory, and ensure your ssh public key are in that directory.

    cd /D %HOMEDRIVE%%HOMEPATH%"/.ssh" (CMD) or

    Set-Location -Path $Env:HOMEDRIVE$Env:HOMEPATH"/.ssh" (PowerShell)

  2. Using scp command

    scp -v -P {{port}} {{source}} {{userID}}@{{instanceIP}}:{{target}}

    In your case

    scp -v "id_rsa.pub" user@host:/home/directory/ then type your password.

  3. If you're using PuTTY there are similar command pscp.

You could check the file on target machine.

Courtyard answered 13/10 at 2:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.