Sunday 29 December 2019

macos - rsync over SSH with cron in osx-environment


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?



Answer




  1. Run ssh-keygen and accept the defaults in every step

  2. cat ~/.ssh/id_rsa.pub | ssh username@host.com "mkdir -p ~/.ssh/; cat >> ~/.ssh/authorized_keys; chmod 700 ~/.ssh/; chmod 600 ~/.ssh/authorized_keys"

  3. Edit the crontab with crontab -e and add a line like 20 4,16 * * * rsync -a someuser@somehost.com:somedir/subdir ~/somedir


No comments:

Post a Comment

How can I VLOOKUP in multiple Excel documents?

I am trying to VLOOKUP reference data with around 400 seperate Excel files. Is it possible to do this in a quick way rather than doing it m...