Search code examples
shellscp

Force SCP not to prompt for password


I'm writing script to test unix commands. one of them is the SCP command, where the certs are set up , so it did not ask for the password on normal scenario.

scp /tmp/test.txt  $userid@$hostname:$path

But assume scenario like certs were deleted or the user id is wrong then the script is not getting completed as scp asks for password

On the terminal

 scp /tmp/test.txt $userid@$hostname:$path
 Password: 

So how can i force not to prompt for password and just fail in case it can not validate.

The scp command was stored in a variable line and is executed as below

`$line`

Solution

  • Typically:

    scp -o BatchMode=yes ..