How to pass the password as input parameter to scp

Dear all

Does anybody know how to pass the password as input parameter to scp or rsync in unix scripts?

I have tried echo <password> | scp filename username@<ip address>:/filepath/ .
But it does not work.

BTW, I dont want to setup ssh trust between servers in this adhoc task.

Regards,
eldon

scp and rsync are designed to detect that their password input isn't comming from a terminal to stop just this sort of thing.

I would say the developers of these products thought it was a bad thing for account passwords being visible on ps listings or in human readable files.

If you really insist on doing this sort of thing the expect tool is probably the way you will need to go, or just setup public/private key authentication between the accounts (it's not that hard and will be much more portable/safe).

One reason those methods of authentication are not considered as worthwhile is that they mean you are keeping your password or passphrase stored somewhere in the clear, or in a way a program can decrypt them without verifying you are there. But for automated things, sometimes you just have to do some of this.

I recommend using keys with ssh. You can encrypt the private keys with a passphrase that ssh-agent can open for you once (per reboot or login) and all further uses, like the overnight backup, can just get it from the agent. Or if you trust your machine's physical security (not recommended for laptops taken from home or office) just leave it unencrypted. You can also do what I do and have authorize two or more extra keys at the login destination and hide extras on USB memory sticks with obscure names. Other options include have separate keys for interactive access and automated access (if the automated access key gets into someone else's hands you still have your server access via the interactive key with you you can revoke the authentication of the other key, and put in a new one).