There are several options:
- using sshpass
Execute the command:
sshpass -p 'password' scp filename user@host:
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
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)
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
scp operation without having to enter a password.