Using Public Keys on many remote PCs
I am trying to write a batch script using WinSCP to transfer files via SFTP. I have about 50 remote PCs that act as a server for an inside network at offsite locations. Each of these servers can have anywhere from 1 to 8 clients on it. These clients run schtasks overnight, one of which is a batch file that gets and puts several different files to/from the Server. Currently, they use FTP. I now need to re-write the FTP part of the batch file to use SFTP instead. These are Windows 7 Clients, but the Servers are Linux PCs. This is my first time attempting to use WinSCP. I installed it on my own test PC. I created a .dat file in the batch script similar to below -
I have a test Server/Client setup at my desk, so I tested using WinSCP for the first time to see whether it would connect by using the command -
And at first it said I needed a hostkey and WinSCP actually gave me the hostkey in the results. So I added the -hostkey "sshxxxxxxxxxx" switch at the end of first line in the .dat file and tried again to see if it would connect. It got further than before - no longer asking for the hostkey, but the results I got included:
Two questions: Since I won't know the hostkey on these 50 remote servers, how can I write the script to connect not knowing the hostkey?
If I am able to generate a hostkey for the initial SFTP connection, how do I authenticate with either publickey, gssapi-keyex, gssapi--with-mic?
And please be kind as this is my first time using WinSCP and trying to understand keygen and hostkey/publickey authentication.
------------------EDIT-----------------
I did find I can generate a public key if I use the command:
in the correct directory. But I'm not sure how to utilize that within my batch script or WinSCP.
echo open sftp://username:password > C:\temp\temp.dat echo cd /cygdrive/c/pathToUse >> C:\temp\temp.dat echo put %USERDOMAIN%.ftp >> C:\temp\temp.dat echo put File1.txt File1.ftp >> C:\temp\temp.dat echo get File2.txt >> C:\temp\temp.dat echo get File3.txt >> C:\temp\temp.dat echo quit >> C:\temp\temp.dat echo exit >> C:\temp\temp.dat
I have a test Server/Client setup at my desk, so I tested using WinSCP for the first time to see whether it would connect by using the command -
winscp.com /script=ftpcmd.dat
And at first it said I needed a hostkey and WinSCP actually gave me the hostkey in the results. So I added the -hostkey "sshxxxxxxxxxx" switch at the end of first line in the .dat file and tried again to see if it would connect. It got further than before - no longer asking for the hostkey, but the results I got included:
"Server offered these authentication methods: publickey, gssapi-keyex,gssapi-with-mic"
Two questions: Since I won't know the hostkey on these 50 remote servers, how can I write the script to connect not knowing the hostkey?
If I am able to generate a hostkey for the initial SFTP connection, how do I authenticate with either publickey, gssapi-keyex, gssapi--with-mic?
And please be kind as this is my first time using WinSCP and trying to understand keygen and hostkey/publickey authentication.
------------------EDIT-----------------
I did find I can generate a public key if I use the command:
ssh-keygen -y -f ssh_host_rsa_key
in the correct directory. But I'm not sure how to utilize that within my batch script or WinSCP.