I want to automatically download files and folders from a Linux server to which I have an SSH (and FTP) account. The files shall be downloaded on a regular basis (I suppose a cron is the right tool to do so) onto an OS X machine.

I tried the following rsync command, which works fine:

rsync -avzbe ssh account@server.tld:/www/htdocs/something/somefolder /Users/me/folder/foo/

However I have to enter the account's password every time (the SSH account on the server machine). The server is a managed one and I'm afraid I can't change the password.

Here are my questions:

  • How do I bypass the entering of the password by storing it somewhere
  • How do I automate this then correctly?
link|improve this question
feedback

migrated from stackoverflow.com Oct 24 '11 at 13:55

This question came from our site for professional and enthusiast programmers.

2 Answers

up vote 0 down vote accepted

Create a passphraseless SSH key pair

ssh-keygen

Give the remote host the public key

Option 1: pubkey="$(cat ~/.ssh/id_rsa.pub)"; ssh someuser@somehost.com "umask 0077; mkdir -p ~/.ssh; echo "$pubkey" >> ~/.ssh/authorized_keys2"

Option 2: brew install ssh-copy-id; ssh-copy-id -i someuser@somehost.com


crontab -e

20 4,16 * * * rsync -a someuser@somehost.com:somedir/subdir ~/somedir
# download somedir every day at 4:20 AM and 4:20 PM
link|improve this answer
feedback

You have 2 options,

link|improve this answer
The second one looks promising, I will give it a try. Thanks. – Martin Oct 24 '11 at 10:10
You can both vote and accept the answer later – Joao Figueiredo Oct 24 '11 at 10:29
I'd strongly recommend the first option; having passwords sitting around in plaintext is always a bad idea. There's somewhat less security exposure if someone steals an SSH private key. – Gordon Davisson Oct 24 '11 at 16:28
Agreed. There are some real world weird touchy clients who don't allow other companies to edit even one file in their servers though.. I've suggested that as an alternative as I interpreted Martin has his hands tied considering any change in the remote host: "The server is a managed one and I'm afraid I can't change the password ...How do I bypass the entering of the password by storing it somewhere" – Joao Figueiredo Nov 3 '11 at 11:44
feedback

Your Answer

 
or
required, but never shown

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