This question already has an answer here:

I have enabled private key based access to my server. I have generated the certificates with a passphrase.

So to ssh to that machine I have to do -

$ ssh -i .ssh/id_rsa_server foo@example.com

and It asks me for my passphrase before allowing access to the server -

Enter passphrase for key '/home/magic/.ssh/id_server':

When I want to copy a file from server, I do -

$ scp -i id_rsa_server foo@example.com:~/backups/dailyHeavyBkp_21112013.sql.lzma ~/backup

It again asks me for the passphrase. I want to avoid this. I know I can avoid this with an empty passphrase but I don't want that.

Because I am going to put scp ... as a cronjob I don't want it to ask for passphrase. How do I do that?

marked as duplicate by slm, Anthon, rahmu, jasonwryan, Gilles Nov 21 '13 at 23:33

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • @slm Not a duplicate. That question is about using an ssh key agent. This question is about running scp from a cron job. You can't use a key agent with cron (well technically you could, but it'd be pointless as you'd have to rebuild the key ring every single time cron ran). – Patrick Nov 21 '13 at 15:18
  • @HussainTamboli You want to run this in an automated fashion, but you don't want an empty password. What do you want to happen? Store the password in the cron job? Thats no better than having an empty password (debatably worse). Your best route would be a dedicated key for this only, an empty password, and then on the remote host lock the key down to scp only. – Patrick Nov 21 '13 at 15:23
  • 1
    @Patrick - See your point. You could provide the passphrase during the initial startup of the system (I wouldn't do it this way either), or passphrase-less are your only options here. This might of been a better candidate for dup: unix.stackexchange.com/questions/43827/… – slm Nov 21 '13 at 16:03
  • @slm I agree there are lots of duplicate questions on this, but I'm not too fond with the answers on any of them. In my opinion, a proper answer would cover the locking the key down to a specific command. However scp can be quite problematic to lock down to a specific command as the remote filename is part of that command, so scp wouldn't be able to change the remote file name. There are ways of solving this, but I can't find an answer which covers it well. If I get some time, I can put one together. – Patrick Nov 21 '13 at 17:26
  • Thanks. The answers from the duplicate function were really helpful. I think keychain will do. But If that's not convenient I'll go with passphrase-less authentication. – Hussain Tamboli Nov 22 '13 at 5:44