问题
I have a shell script which is performing some renaming and archiving steps. I have added sftp commands to copy multiple files. But when i try to login to the remote machine thru putty it asks for confirmation like Are you sure you want to continue connecting (yes/no)? . I need to enter yes. but since this is being done thru the script am not sure how to do it. below is the script i am using
cd <File Source Location>
sftp user1@remoteserver
sftp> cd <target location to be copied>
sftp> mput *.gz
quit
how to i pass yes in the above code after sftp user1@remoteserver
is executed.
Any help is much appreciated.
回答1:
I think that you are trying to solve the wrong problem.
sftp
asks you for confirmation because it does not know the key of the host yet. Therefore you need to add it to you known_hosts
file like this
ssh-keyscan -H remoteserver >> ~/.ssh/known_hosts
I recommend using scp
command instead of sftp
as it will do all you want in one step.
scp somewhere/*.gz user1@remoteserver:somewhere/else
If for some reason you don't want to do it. You may consider a very insecure command
sftp -o StrictHostKeyChecking=no user1@remoteserver
By using the command above you are vulnerable to Man in the Middle attack, you've been warned.
来源:https://stackoverflow.com/questions/19420253/how-to-add-confirm-in-shell-script-in-sftp-mode