How to use scp in a bash script without specifying password?

19,805

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:
19,805

Related videos on Youtube

morpheous
Author by

morpheous

Updated on September 17, 2022

Comments

  • morpheous
    morpheous over 1 year

    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

  • Stephen
    Stephen about 13 years
    ...and it's dead - was it hostingrails.com/HowTo-SSH-SCP-without-a-password or is there a better page?
  • David Spillett
    David Spillett about 13 years
    I've updated the link to point to a copy archived by the WayBackMachine.
  • TheVillageIdiot
    TheVillageIdiot almost 13 years
    was going to ask just this question as I am being prompted for passphrase :D will have to setup keys without passphrase now.