There are several options:
- using sshpassusing sshpass
Execute the command:
sshpass -p 'password' scp filename user@host:
Install sshpass:
Ubuntu:
sudo apt install sshpass
sudo apt install sshpass
sshpass - noninteractive ssh password provider
sshpass is a utility designed for running ssh using the mode referred to as "keyboard-interactive" password authentication, but in non-interactive mode.
ssh uses direct TTY access to make sure that the password is indeed issued by an interactive keyboard user. Sshpass runs ssh in a dedicated tty, fooling it into thinking it is getting the password from an interactive user.
The command to run is specified after sshpass' own options. Typically it will be "ssh" with arguments, but it can just as well be any other command. The password prompt used by ssh is, however, currently hardcoded into sshpass.
using expect (or other script)
Using ssh with key-pair (instead of using password)
Using expect (or other script)
write a script which will inject the password once it will identify the ssh password prompt
- Using ssh with key-pair (instead of using password)
IMHO - This is the most secure way, and it doesn't require using passwords.
Using public/private key in order to perform ssh or scp operation without having to enter a password.
More info can be found in this answer
Detailed information can be found here