I have a Linux machine, and I need to sftp to a Windows SFTP server. So for first step, I create my own id_rsa
file and the id_rsa.pub
in my Linux machine.
Then I copy the text in the id_rsa.pub
into the id_rsa.pub
in the SFTP server.
And the sftp
connection work correctly.
However, I would like to ask about the command to copy the public key from client to server. I have search in google and I get a command which is:
ssh-copy-id -i id_rsa.pub ftp_user*@10.7.8.32
But I hit the following error:
'exec' is not recognized as an internal or external command, operable program or batch file.
The system cannot find the path specified.
I believe there is some command exits for this right? Instead of I copy the public key manually to the SFTP server.
The SFTP version is SFTP protocol version 3.
Best Answer
ssh-copy-id
script works only against *nix servers (or servers with *nix emulation), as it internally executes some *nix shell command on the server (likeexec
,sh
,umask
,rm
,mkdir
,tail
,cat
, etc).You can setup the key manually. I'm aware that you know that, but as there subtle differences, when doing that on a Windows server, I'll mention it anyway for benefit of other readers.
Main steps are:
.ssh
folder in your Windows account profile folder (typically inC:\Users\username\.ssh
).authorized_keys
file in the folder and add your public key to it..ssh
folder and theauthorized_keys
so that only a respective Windows account have a write access to the folder and the file and the account that runs the server have a read access. Also note that the location of the file for Administrators is overriden in the defaultsshd_config
file to%ALLUSERSPROFILE%\ssh\administrators_authorized_keys
.For details, see my guide for Setting up SSH public key authentication on Win32-OpenSSH.
If you want to do that from your local machine, you can do it using
sftp
. Particularly if you have no key on the server registered yet, you can just upload theid_rsa.pub
file asauthorized_keys
file:The above is basically, what
ssh-copy-id
does internally – Except thatssh-copy-id
appends theauthorized_keys
, what plainsftp
cannot do. If you need to append, you can downloadauthorized_keys
to the local machine, append it locally and re-upload it back.Alternatively, you you can setup the key from another Windows machine using (my) WinSCP client, with its Install Public Key into Server function.
See also my answer to Setting up public key authentication to Linux server from Windows (ppk private key).