4

I have a file in server A which I am able to do transfer to server B using scp. I need to do this through a cron entry. server B has a password. How do I perform this?

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
Karthik
  • 57
  • 1
  • 1
  • 7

2 Answers2

8

Don't use password authentication. Use ssh keypairs.

Karthik@A $: ssh-keygen    #keep the passphrase empty
Karthik@A $: ssh-copy-id B #enter your B password
#^ this will copy your public key to Karthik@B:.ssh/authorized_keys

From then on, you should be able to ssh from A to B (and by extension, scp from A to B) without a password.

Petr Skocik
  • 28,176
  • 14
  • 81
  • 141
  • And, for extra security, you can [restrict the commands that the key is allowed to run](http://unix.stackexchange.com/questions/214283/should-the-key-for-an-automatically-running-cron-job-that-runs-over-ssh-not-have), and even [what directories it can access with scp](http://unix.stackexchange.com/questions/9853/restricting-an-ssh-scp-sftp-user-to-a-directory). – Gilles 'SO- stop being evil' Jul 08 '15 at 22:44
  • is there a detailed document from where I can follow the steps. I'm new to unix. – Karthik Jul 20 '15 at 10:21
0

Generate an ssh-key on server A using ssh-keygen. This will generate a private and public key pair in $HOME/.ssh. Add the public key to the $HOME/.ssh/authorized_keys file on server B.

You can use the man command to get more information. The command man authorized_keys will present the manual page that discusses authorized keys.

Try the following sites for discussions:

BillThor
  • 8,887
  • 22
  • 27