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?
The scp tool relies on SSH (Secure Shell) to transfer files, so all you need is the username and password for the source and target systems. Another advantage is that with SCP you can move files between two remote servers, from your local machine in addition to transferring data between local and remote machines.
The SCP command; on its own, is not sufficient enough to accommodate password authentication under a one-line command usage and therefore leads to a successive password prompt for the OS user to enter the required login passcode.
Introduction. SCP stands for Secure Copy Protocol. It is a tool that can be used to transfer files from a local host to a remote host, from a remote host to a local host, or between two remote hosts.
Just pass with sshpass -p "your password"
at the beginning of your scp
command
sshpass -p "your password" scp ./abc.txt hostname/abc.txt
// copy /tmp/abc.txt to /tmp/abc.txt (target path)
// username and password of 10.1.1.2 is "username" and "password"
sshpass -p "password" scp /tmp/abc.txt [email protected]:/tmp/abc.txt
// install sshpass (ubuntu)
sudo apt-get install sshpass
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With