How to respond to password prompt when using SCP in a shell script?

derrdji picture derrdji · Sep 22, 2009 · Viewed 36.2k times · Source

First of all, I am well aware of that there are many of questions regarding this topic. I have read them, but still could figure out an appropriate answer for my situation.

I would like to scp the entire ~/cs###/assign1 dir from local to school home dir with a shell script. My question is, is there a way in my script to wait for the password prompt, and then simulate key board event to 'type' in my password?


here is a really detailed guide of how to set up the key

Answer

KevinS picture KevinS · Dec 19, 2012

Use "sshpass"!

#!/bin/bash
sshpass -p "password" scp -r /some/local/path [email protected]:/some/remote/path