We always need to enter a password when copying files from one server to another. And the command scp
does not provide parameters to carry password to another server. That’s very inconvenient, especially when we writing shells.
There is a tool that can solve this problem named sshpass
. You can use it into your shells and don’t need to enter the password.
It’s super simple to use, you only add the sshpass
command to the front of your command line of scp or ssh as follow:
sshpass -p password scp -P port source_file target_file
It’s also simple to install. There are two common ways to install ‘sshpass’ as follow:
# centos
yum install -y sshpass
# ubuntu
apt install -y sshpass