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 am a bash newbie, and am writing a bash script that will allow transfer of files between two computers. BTW, is there a more secure alternative to scp?

Currently, I am doing this manually, by using scp. The remote server always prompts me for the password, and I supply that. I want to automate this (hence the bash script). However, I dont want to supply my password in plain text (or if at all - I was under the impression that open SSL does away with passwords and uses certificates etc?).

Can anyone please explain how I can automate my current process, without explicitly displaying my password.

I am running on Ubuntu 10.0.4

share|improve this question

To login without password you need to setup key-based authentication. There are a number of tutorials out there - this one looks like a good place to start (edit: the original site fell of the Internet, this link is to the last copy archived by the WayBackMachine).

If you put a passphrase on your key (recommended) you will still need to provide that when you login but you can use ssh-agent to reduce the amount of times you have to provide it.

If you need scripts that use SSH/SCP to run unattended then you need to not have a passphrase on your key, but in this case you absolutely must keep that key file secure such that no-one else can read it otherwise they will be able to authenticate on that server as you without any password/passphrase.

share|improve this answer
+1 for the link. I am reading it now ... – morpheous Aug 5 '10 at 8:46
...and it's dead - was it or is there a better page? – Stephen Mar 29 '11 at 1:44
I've updated the link to point to a copy archived by the WayBackMachine. – David Spillett Mar 29 '11 at 15:44
was going to ask just this question as I am being prompted for passphrase :D will have to setup keys without passphrase now. – TheVillageIdiot Jun 8 '11 at 17:01

supply a password to scp

Piping your password to the standard input of scp won't work:

echo "password" | scp file user@host:/dir/to/copy/to

because scp doesn't read from the standard input for security reasons.

Use the tool sshpass instead:

You may have to install sshpass as root since it is non standard.

sshpass -p 'mypassword' scp -r /home/b/bar.txt
share|improve this answer

You must log in to answer this question.

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