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 user@abc.com:/usr/etc/Output/*.txt /usr/abc/  
user@abc.com's password:

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.

| improve this answer | |
  • 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 – Mohsen El-Tahawy Oct 27 '17 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 '17 at 8:28

you can use this: sshpass -p 'your_password' scp user@abc.com:/usr/etc/Output/*.txt /usr/abc/ but remember that you store password in plaintext.

| improve this answer | |

Follow fduff’s answer, but when you run keygen, press enter when it requests a password. This will create a key that does not require password entry when it is used.

| improve this answer | |

One can use the following command:

scp -r user@abc.com:/usr/etc/Output/*.txt /usr/abc/

And also setup the ssh key based auth to ask no password during scp.

| improve this answer | |
  • I use scp -r user@abc.com:/usr/etc/Output/*.txt /usr/abc/ but it also ask for password @Muralibabud – Nishat Jan 28 '16 at 9:27
  • @Nishat use ssh-keygen and ssh-copy-id user@abc.com as fduff posted above – Muralibabud Jan 28 '16 at 10:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.