Search code examples
shellunixkshscp

how to prevent scp/ssh from trying to read standard input


I am passing a file from one server to another using authorized keys. However, in the event keys are no longer valid, the script is being asked for the password on and on.

I have tried

scp ${user}@$host}:/tmp ./file1 </dev/null

but I still get the prompt. The only time when this works is if I run it off schedule like this:

echo "scp ${user}@$host}:/tmp ./file1" | at now

In this case it will correctly error out if keys are no longer valid.

But how can I create a blank input stream, that will not be prompting the user if the script is run interactively?

@David:

echo "" | scp ${user}@${host}:/tmp ./file1 </dev/null 

didn't help, same response, so it may need to have an stty command to zero tty input, I'm guessing now, per Kenster's note.


Solution

  • But how can I create a blank input stream, that will not be prompting the user if the script is run interactively?

    Instead of that disable password authentication.

    scp -o BatchMode=yes -o PasswordAuthentication=no -o PubkeyAuthentication=yes ...