问题
I am building a batch file so that I can push firmware to 600 plus devices.
If I am at a command prompt I can run the following command on a single line that will push the firmware and answer yes to the SSH key prompt.
echo y | pscp -v -scp -pw password C:\CNA1000\Firmware\CNA1504v1.1.7\CNA1504v1_1_7.run root@192.168.1.1:/tmp/.
The echo y | answers yes to the SSH keys prompt. However when I try to add it to a batch file I get an error in the command prompt that it did not like the password.
Specifically, it looks like this;
Using username "root".
root@192.168.1.1's password:
Sent password
Access denied
Access denied
and then it repeats itself until I hit CTRL+C to break the batch file.
Is there a better way to do this so that I can automate the process?
Thanks,
回答1:
Do not blindly answer "y", you lose a protection against man-in-the-middle attacks.
You should use the -hostkey switch with your host key fingerprint.
Actually it's the same with WinSCP, that you ended up using. WinSCP open command also has the -hostkey
switch.
If it does work without the -hostkey
switch, it's because the host key is cached in Windows registry from some previous interactive use of WinSCP.
Similarly, that's the same with pscp. Had you used PuTTY or pscp (or any other tools from PuTTY suite) before interactively and had you confirmed the host key, it would get cached. And later automatic uses would pass without confirmation.
回答2:
I ended up using WinSCP.net for the batch file to correctly do what I was trying to do. Here is the example of how to do the above with WinSCP.net.
@echo off
"C:\Program Files (x86)\WinSCP\WinSCP.com" ^
/log="C:\Program Files (x86)\WinSCP\WinSCP.log" /ini=nul ^
/command ^
"open scp://root:root@192.168.1.1/" ^
"Put C:\CNA1000\Firmware\CNA1504v1.1.7\CNA1504v1_1_7.run /tmp/." ^
"exit"
set WINSCP_RESULT=%ERRORLEVEL%
if %WINSCP_RESULT% equ 0 (
echo Success
) else (
echo Error
)
exit /b %WINSCP_RESULT%
And repeat for each IP address.
来源:https://stackoverflow.com/questions/39924091/using-echo-y-as-an-automated-response-to-a-pcp-hostkey-prompt