Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

How to pass password to scp?

I know it is not recommended, but is it at all possible to pass the user's password to scp?

I'd like to copy a file via scp as part of a batch job and the receiving server does, of course, need a password and, no, I cannot easily change that to key-based authentication.
by

3 Answers

espadacoder11
You can script it with a tool like expect (there are handy bindings too, like Pexpect for Python).
pankajshivnani123
just generate a ssh key like:

ssh-keygen -t rsa -C "your_email@youremail.com"

copy the content of ~/.ssh/id_rsa.pub and lastly add it to the remote machines ~/.ssh/authorized_keys

make sure remote machine have the permissions 0700 for ~./ssh folder and 0600 for ~/.ssh/authorized_keys
kshitijrana14
If you are connecting to the server from Windows, the Putty version of scp ("pscp") lets you pass the password with the -pw parameter.

Login / Signup to Answer the Question.