Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to copy from remote box with scp, while the fact that each time I have to re-enter password is annoying. So I store my password in plain text and expect the following code should work

scp -Pport_num username@hostname:path_to_file local_path < passwd

After googling, I know this target can be achieved with the help of expect but I can't figure out why input redirection will fail.

Thanks and best regards.

share|improve this question
up vote 4 down vote accepted

scp isn't looking for anything from standard input, so passing your password this way won't help. Yes, expect can be used in a case like this, but you'd be better off authenticating via public key -- either with a specific password-less public/private keypair, or using an ssh agent in your current session.

So many tutorials out there, including: this one

share|improve this answer
Thanks for your fast response. "scp isn't looking for anything from standard input". Then where does our input go? And where will scp look for input? Thank you again. – Summer_More_More_Tea Jun 21 '12 at 6:03
Your redirected file just goes into the "bit bucket", to nowhere, much as it would with the command echo "Hello" < passwd. scp (or ssh) will ask for password if necessary, but do not take that from stdin. ssh will send stdin to the command on the remote machine; I don't think scp uses stdin at all. – Lars Rohrbach Jun 21 '12 at 6:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .