Send password when using scp to copy files from one server to another

cherry2891 picture cherry2891 · Dec 6, 2013 · Viewed 165.7k times · Source

using scp to copy files from 1 unix server to another regularly and performing certain actions. to do this quickly I wish to use a unix script which does the scp and inputs the password required to complete the scp.

I have tried the expect command to send the password throught the unix command line however unable to achieve this so far.

sample commands

scp ./abc.txt hostname/abc.txt
expect "*password:*"
send "mypassword\r"

I get these errors:

couldn't read file "password: ": no such file or directory
myscript.sh[5]: send: not found [No such file or directory]

am I missing something?

Answer

Akki picture Akki · Jan 16, 2014

Just pass with sshpass -p "your password" at the beginning of your scp command

sshpass -p "your password" scp ./abc.txt hostname/abc.txt