Alex Rivera | Logout

How to pass password to scp?

Asked 2008-09-08T16:35:09.230
488

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.

Edit
Report

1 Answer

784

Use sshpass:

sshpass -p "password" scp -r user@example.com:/some/remote/path /some/local/path

or so the password does not show in the bash history

sshpass -f "/path/to/passwordfile" scp -r user@example.com:/some/remote/path /some/local/path

The above copies contents of path from the remote host to your local.

Install :

  • ubuntu/debian
  • apt install sshpass
  • centos/fedora
  • yum install sshpass
  • mac w/ macports
  • port install sshpass
  • mac w/ homebrew
  • brew install sshpass
answered 2012-12-19T15:17:15.563

Your Answer