17

I'm facing problem when I pull a file from another machine to my machine using SCP. File is successfully transferred but each time it asks for password. I want to run this SCP command as a cronjob, How can I save password for this automation?

scp [email protected]:/usr/etc/Output/*.txt /usr/abc/  
[email protected]'s password:
0

3 Answers 3

26

You can do:

  1. (if not already done) generate a set of public and private ssh keys on your machine for your user with:

    $ ssh-keygen

    Answer the questions in order to generate the set of keys.

  2. copy your public key to the remote host:

    $ ssh-copy-id remote-user@remote-host

    This will enable login-in from your username@host to remote-user@remote-host without being prompt with p/w authentication.

2
  • what do you mean in step 2? you mean to copy the created file in step one to the machine from which I want to copy a file Oct 27, 2017 at 17:25
  • @MohsenEl-Tahawy, ssh-copy-id will take care of copying the encrypted credentials onto the remote host, that way it won't prompt for p/w next time that user ssh onto it.
    – fduff
    Oct 30, 2017 at 8:28
9

you can use this: sshpass -p 'your_password' scp [email protected]:/usr/etc/Output/*.txt /usr/abc/ but remember that you store password in plaintext.

1

My version of ssh-copy-id requires '-i' option to work, or else it will assume copying credentials from ssh-agent, which will not work if you are not using it.

ssh-copy-id -i $myfile.pub remote-user@remote-host

You must log in to answer this question.

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