{"id":337,"date":"2013-04-19T06:52:50","date_gmt":"2013-04-19T06:52:50","guid":{"rendered":"https:\/\/shan.info\/new\/using-rsync-and-ssh\/"},"modified":"2013-04-19T06:52:50","modified_gmt":"2013-04-19T06:52:50","slug":"using-rsync-and-ssh","status":"publish","type":"post","link":"https:\/\/shan.info\/new\/using-rsync-and-ssh\/","title":{"rendered":"Using Rsync and SSH"},"content":{"rendered":"<div class=\"abstract\" style=\"margin: 10px 30px; font-size: 13px; font-family: arial, helvetica;\">This document covers using cron, ssh, and rsync to backup files over a local network or the Internet. Part of my goal is to ensure no user intervention is required when the computer is restarted (for passwords, keys, or key managers).<\/div>\n<div class=\"normal\" style=\"padding-bottom: 10px; padding-right: 10px; font-family: arial, helvetica; font-size: medium;\">I like to backup some logging, mail, and configuration information sometimes on hosts across the network and Internet, and here is a way I have found to do it. You&#8217;ll need these packages installed:<\/p>\n<ul>\n<li>rsync<\/li>\n<li>openssh<\/li>\n<li>cron (or vixie-cron)<\/li>\n<\/ul>\n<p>Please note these instructions may be specific to Red Hat Linux versions 7.3, 9, and Fedora Core 3, but I hope they won&#8217;t be too hard to adapt to almost any *NIX type OS. The man pages for &#8216;ssh&#8217; and &#8216;rsync&#8217; should be helpful to you if you need to change some things (use the &#8220;man ssh&#8221; and &#8220;man rsync&#8221; commands).<\/p><\/div>\n<div class=\"normal\" style=\"padding-bottom: 10px; padding-right: 10px; font-family: arial, helvetica; font-size: medium;\">First, I&#8217;ll define some variables. In my explanation, I will be synchronizing files (copying only new or changed files) one way, and I will be starting this process from the host I want to copy things to. In other words, I will be syncing files from \/remote\/dir\/ on&nbsp;<em>remotehost<\/em>, as&nbsp;<em>remoteuser<\/em>, to \/this\/dir\/ on&nbsp;<em>thishost<\/em>, as&nbsp;<em>thisuser<\/em>.<\/div>\n<div class=\"normal\" style=\"padding-bottom: 10px; padding-right: 10px; font-family: arial, helvetica; font-size: medium;\">I want to make sure that &#8216;rsync&#8217; over &#8216;ssh&#8217; works at all before I begin to automate the process, so I test it first as&nbsp;<em>thisuser<\/em>:<\/p>\n<div class=\"console\" style=\"font-family: courier, times; font-size: 13px; margin: 10px 30px; padding: 10px; border: 2px solid black;\">$ rsync -avz -e ssh remoteuser@remotehost:\/remote\/dir \/this\/dir\/&nbsp;<\/div>\n<p>and type in&nbsp;<em>remoteuser<\/em>@<em>remotehost<\/em>&#8216;s password when prompted. I do need to make sure that&nbsp;<em>remoteuser<\/em>&nbsp;has read permissions to \/remote\/dir\/ on&nbsp;<em>remotehost<\/em>, and that&nbsp;<em>thisuser<\/em>&nbsp;has write permissions to \/this\/dir\/ on<em>thishost<\/em>. Also, &#8216;rsync&#8217; and &#8216;ssh&#8217; should be in&nbsp;<em>thisuser<\/em>&#8216;s path (use &#8220;which ssh&#8221; and &#8220;which rsync&#8221;), &#8216;rsync&#8217; should be in&nbsp;<em>remoteuser<\/em>&#8216;s path, and &#8216;sshd&#8217; should be running on&nbsp;<em>remotehost<\/em>.<\/div>\n<div class=\"normal\" style=\"padding-bottom: 10px; padding-right: 10px; font-family: arial, helvetica; font-size: medium;\">\n<div class=\"secondary-heading\" style=\"font-size: 24px;\">Configuring&nbsp;<em>thishost<\/em><\/div>\n<p>If that all worked out, or I eventually made it work, I am ready for the next step. I need to generate a private\/public pair of keys to allow a &#8216;ssh&#8217; connection without asking for a password. This may sound dangerous, and it is, but it is better than storing a user password (or key password) as clear text in the script&nbsp;<a style=\"color: #000077; text-decoration: none; background-color: transparent;\" name=\"ref0\" href=\"http:\/\/troy.jdmz.net\/rsync\/index.html#note0\">[0]<\/a>. I can also put limitations on where connections made with this key can come from, and on what they can do when connected. Anyway, I generate the key I will use on&nbsp;<em>thishost<\/em>&nbsp;(as&nbsp;<em>thisuser<\/em>):<\/p>\n<div class=\"console\" style=\"font-family: courier, times; font-size: 13px; margin: 10px 30px; padding: 10px; border: 2px solid black;\">$ ssh-keygen -t rsa -b 2048 -f \/home\/thisuser\/cron\/thishost-rsync-key&nbsp;<br \/>Generating public\/private rsa key pair.&nbsp;<br \/>Enter passphrase (empty for no passphrase): [press enter here]&nbsp;<br \/>Enter same passphrase again: [press enter here]&nbsp;<br \/>Your identification has been saved in \/home\/thisuser\/cron\/thishost-rsync-key.&nbsp;<br \/>Your public key has been saved in \/home\/thisuser\/cron\/thishost-rsync-key.pub.&nbsp;<br \/>The key fingerprint is:&nbsp;<br \/>2e:28:d9:ec:85:21:e7:ff:73:df:2e:07:78:f0:d0:a0 thisuser@thishost&nbsp;<\/div>\n<p>and now we have a key with no password in the two files mentioned above&nbsp;<a style=\"color: #000077; text-decoration: none; background-color: transparent;\" name=\"ref1\" href=\"http:\/\/troy.jdmz.net\/rsync\/index.html#note1\">[1]<\/a>. Make sure that no other unauthorized user can read the private key file (the one without the &#8216;.pub&#8217; extension).<\/div>\n<div class=\"normal\" style=\"padding-bottom: 10px; padding-right: 10px; font-family: arial, helvetica; font-size: medium;\">This key serves no purpose until we put the public portion into the &#8216;authorized_keys&#8217; file&nbsp;<a style=\"color: #000077; text-decoration: none; background-color: transparent;\" name=\"ref2\" href=\"http:\/\/troy.jdmz.net\/rsync\/index.html#note2\">[2]<\/a>&nbsp;on&nbsp;<em>remotehost<\/em>, specifically the one for&nbsp;<em>remoteuser<\/em>:<\/p>\n<div class=\"console\" style=\"font-family: courier, times; font-size: 13px; margin: 10px 30px; padding: 10px; border: 2px solid black;\">\/home\/remoteuser\/.ssh\/authorized_keys&nbsp;<\/div>\n<p>I use scp to get the file over to&nbsp;<em>remotehost<\/em>:<\/p>\n<div class=\"console\" style=\"font-family: courier, times; font-size: 13px; margin: 10px 30px; padding: 10px; border: 2px solid black;\">$ scp \/home\/thisuser\/cron\/thishost-rsync-key.pub remoteuser@remotehost:\/home\/remoteuser\/&nbsp;<\/div>\n<p>and then I can prepare things on&nbsp;<em>remotehost<\/em>.<\/div>\n<div class=\"normal\" style=\"padding-bottom: 10px; padding-right: 10px; font-family: arial, helvetica; font-size: medium;\">\n<div class=\"secondary-heading\" style=\"font-size: 24px;\">Configuring&nbsp;<em>remotehost<\/em><\/div>\n<p>I &#8216;ssh&#8217; over to&nbsp;<em>remotehost<\/em>:<\/p>\n<div class=\"console\" style=\"font-family: courier, times; font-size: 13px; margin: 10px 30px; padding: 10px; border: 2px solid black;\">$ ssh remoteuser@remotehost<br \/>remoteuser@remotehost&#8217;s password: [type correct password here]<br \/>$ echo I am now $USER at $HOSTNAME<br \/>I am now remoteuser at remotehost<\/div>\n<p>to do some work.<\/p><\/div>\n<div class=\"normal\" style=\"padding-bottom: 10px; padding-right: 10px; font-family: arial, helvetica; font-size: medium;\">I need to make sure I have the directory and files I need to authorize connections with this key&nbsp;<a style=\"color: #000077; text-decoration: none; background-color: transparent;\" name=\"ref3\" href=\"http:\/\/troy.jdmz.net\/rsync\/index.html#note3\">[3]<\/a>:<\/p>\n<div class=\"console\" style=\"font-family: courier, times; font-size: 13px; margin: 10px 30px; padding: 10px; border: 2px solid black;\">$ if [ ! -d .ssh ]; then mkdir .ssh ; chmod 700 .ssh ; fi&nbsp;<br \/>$ mv thishost-rsync-key.pub .ssh\/&nbsp;<br \/>$ cd .ssh\/&nbsp;<br \/>$ if [ ! -f authorized_keys ]; then touch authorized_keys ; chmod 600 authorized_keys ; fi&nbsp;<br \/>$ cat thishost-rsync-key.pub &gt;&gt; authorized_keys&nbsp;<\/div>\n<p>Now the key can be used to make connections to this host, but these connections can be from anywhere (that the ssh daemon on&nbsp;<em>remotehost<\/em>&nbsp;allows connections from) and they can do anything (that&nbsp;<em>remoteuser<\/em>&nbsp;can do), and I don&#8217;t want that. I edit the &#8216;authorized_keys&#8217; file (with vi) and modify the line with &#8216;thishost-rsync-key.pub&#8217; information on it. I will only be adding a few things in front of what is already there, changing the line from this:<\/p>\n<div class=\"console\" style=\"font-family: courier, times; font-size: 13px; margin: 10px 30px; padding: 10px; border: 2px solid black;\">ssh-dss AAAAB3NzaC1kc3MAAAEBAKYJenaYvMG3nHwWxKwlWLjHb77CT2hXwmC8Ap+fG8wjlaY\/9t4u<br \/>A+2qx9JNorgdrWKhHSKHokFFlWRj+qk3q+lGHS+hsXuvta44W0yD0y0sW62wrEVegz+JVmntxeYc0nDz<br \/>5tVGfZe6ydlgomzj1bhfdpYe+BAwop8L+EMqKLS4iSacNjoPlHsmqHMnbibn3tBqJEq2QJjEPaiYj1iP<br \/>5IaCuYBhuTKQGa+oyH3mXEif5CKdsIKBj46B0tCy0\/GC7oWcUN92QdLrUyTeRJZsTWsxKpRbMliD2pBh<br \/>4oyX\/aXEf8+HZBrO5vQjDBCfTFQA+35Xrd3eTVEjkGkncI0SAeUAAAAVAMZSASmQ9Pi38mdm6oiVXD55<br \/>Kk2rAAABAE\/bA402VuCsOLg9YS0NKxugT+o4UuIjyl6b2\/cMmBVWO39lWAjcsKK\/zEdJbrOdt\/sKsxIK<br \/>1\/ZIvtl92DLlMhci5c4tBjCODey4yjLhApjWgvX9D5OPp89qhah4zu509uNX7uH58Zw\/+m6ZOLHN28mV<br \/>5KLUl7FTL2KZ583KrcWkUA0Id4ptUa9CAkcqn\/gWkHMptgVwaZKlqZ+QtEa0V2IwUDWS097p3SlLvozw<br \/>46+ucWxwTJttCHLzUmNN7w1cIv0w\/OHh5IGh+wWjV9pbO0VT3\/r2jxkzqksKOYAb5CYzSNRyEwp+NIKr<br \/>Y+aJz7myu4Unn9de4cYsuXoAB6FQ5I8AAAEBAJSmDndXJCm7G66qdu3ElsLT0Jlz\/es9F27r+xrg5pZ5<br \/>GjfBCRvHNo2DF4YW9MKdUQiv+ILMY8OISduTeu32nyA7dwx7z5M8b+DtasRAa1U03EfpvRQps6ovu79m<br \/>bt1OE8LS9ql8trx8qyIpYmJxmzIdBQ+kzkY+9ZlaXsaU0Ssuda7xPrX4405CbnKcpvM6q6okMP86Ejjn<br \/>75Cfzhv65hJkCjbiF7FZxosCRIuYbhEEKu2Z9Dgh+ZbsZ+9FETZVzKBs4fySA6dIw6zmGINd+KY6umMW<br \/>yJNej2Sia70fu3XLHj2yBgN5cy8arlZ80q1Mcy763RjYGkR\/FkLJ611HWIA= thisuser@thishost<\/div>\n<p>to this&nbsp;<a style=\"color: #000077; text-decoration: none; background-color: transparent;\" name=\"ref4\" href=\"http:\/\/troy.jdmz.net\/rsync\/index.html#note4\">[4]<\/a>:<\/p>\n<div class=\"console\" style=\"font-family: courier, times; font-size: 13px; margin: 10px 30px; padding: 10px; border: 2px solid black;\">from=&#8221;10.1.1.1&#8243;,command=&#8221;\/home\/remoteuser\/cron\/validate-rsync&#8221; ssh-dss AAAAB3Nza<br \/>C1kc3MAAAEBAKYJenaYvMG3nHwWxKwlWLjHb77CT2hXwmC8Ap+fG8wjlaY\/9t4uA+2qx9JNorgdrWKhH<br \/>SKHokFFlWRj+qk3q+lGHS+hsXuvta44W0yD0y0sW62wrEVegz+JVmntxeYc0nDz5tVGfZe6ydlgomzj1<br \/>bhfdpYe+BAwop8L+EMqKLS4iSacNjoPlHsmqHMnbibn3tBqJEq2QJjEPaiYj1iP5IaCuYBhuTKQGa+oy<br \/>H3mXEif5CKdsIKBj46B0tCy0\/GC7oWcUN92QdLrUyTeRJZsTWsxKpRbMliD2pBh4oyX\/aXEf8+HZBrO5<br \/>vQjDBCfTFQA+35Xrd3eTVEjkGkncI0SAeUAAAAVAMZSASmQ9Pi38mdm6oiVXD55Kk2rAAABAE\/bA402V<br \/>uCsOLg9YS0NKxugT+o4UuIjyl6b2\/cMmBVWO39lWAjcsKK\/zEdJbrOdt\/sKsxIK1\/ZIvtl92DLlMhci5<br \/>c4tBjCODey4yjLhApjWgvX9D5OPp89qhah4zu509uNX7uH58Zw\/+m6ZOLHN28mV5KLUl7FTL2KZ583Kr<br \/>cWkUA0Id4ptUa9CAkcqn\/gWkHMptgVwaZKlqZ+QtEa0V2IwUDWS097p3SlLvozw46+ucWxwTJttCHLzU<br \/>mNN7w1cIv0w\/OHh5IGh+wWjV9pbO0VT3\/r2jxkzqksKOYAb5CYzSNRyEwp+NIKrY+aJz7myu4Unn9de4<br \/>cYsuXoAB6FQ5I8AAAEBAJSmDndXJCm7G66qdu3ElsLT0Jlz\/es9F27r+xrg5pZ5GjfBCRvHNo2DF4YW9<br \/>MKdUQiv+ILMY8OISduTeu32nyA7dwx7z5M8b+DtasRAa1U03EfpvRQps6ovu79mbt1OE8LS9ql8trx8q<br \/>yIpYmJxmzIdBQ+kzkY+9ZlaXsaU0Ssuda7xPrX4405CbnKcpvM6q6okMP86Ejjn75Cfzhv65hJkCjbiF<br \/>7FZxosCRIuYbhEEKu2Z9Dgh+ZbsZ+9FETZVzKBs4fySA6dIw6zmGINd+KY6umMWyJNej2Sia70fu3XLH<br \/>j2yBgN5cy8arlZ80q1Mcy763RjYGkR\/FkLJ611HWIA= thisuser@thishost<\/div>\n<p>where &#8220;10.1.1.1&#8221; is the IP (version 4&nbsp;<a style=\"color: #000077; text-decoration: none; background-color: transparent;\" name=\"ref5\" href=\"http:\/\/troy.jdmz.net\/rsync\/index.html#note5\">[5]<\/a>) address of&nbsp;<em>thishost<\/em>, and &#8220;\/home\/remoteuser\/cron\/validate-rsync&#8221; (which is just one of a few options&nbsp;<a style=\"color: #000077; text-decoration: none; background-color: transparent;\" name=\"ref6\" href=\"http:\/\/troy.jdmz.net\/rsync\/index.html#note6\">[6]<\/a>, including customization&nbsp;<a style=\"color: #000077; text-decoration: none; background-color: transparent;\" name=\"ref7\" href=\"http:\/\/troy.jdmz.net\/rsync\/index.html#note7\">[7]<\/a>&nbsp;to enhance security) is a script that looks something like this&nbsp;<a style=\"color: #000077; text-decoration: none; background-color: transparent;\" name=\"validate-rsync\" href=\"http:\/\/troy.jdmz.net\/rsync\/index.html\"><\/a>:<\/p>\n<div class=\"console\" style=\"font-family: courier, times; font-size: 13px; margin: 10px 30px; padding: 10px; border: 2px solid black;\">#!\/bin\/sh&nbsp;<\/p>\n<p>case &#8220;$SSH_ORIGINAL_COMMAND&#8221; in&nbsp;<br \/>*&amp;*)&nbsp;<br \/>echo &#8220;Rejected&#8221;&nbsp;<br \/>;;&nbsp;<br \/>*(*)&nbsp;<br \/>echo &#8220;Rejected&#8221;&nbsp;<br \/>;;&nbsp;<br \/>*{*)&nbsp;<br \/>echo &#8220;Rejected&#8221;&nbsp;<br \/>;;&nbsp;<br \/>*;*)&nbsp;<br \/>echo &#8220;Rejected&#8221;&nbsp;<br \/>;;&nbsp;<br \/>*&lt;*)&nbsp;<br \/>echo &#8220;Rejected&#8221;&nbsp;<br \/>;;&nbsp;<br \/>*`*)&nbsp;<br \/>echo &#8220;Rejected&#8221;&nbsp;<br \/>;;&nbsp;<br \/>*|*)&nbsp;<br \/>echo &#8220;Rejected&#8221;&nbsp;<br \/>;;&nbsp;<br \/>rsync &#8211;server*)&nbsp;<br \/>$SSH_ORIGINAL_COMMAND&nbsp;<br \/>;;&nbsp;<br \/>*)&nbsp;<br \/>echo &#8220;Rejected&#8221;&nbsp;<br \/>;;&nbsp;<br \/>esac&nbsp;<\/div>\n<p>If&nbsp;<em>thishost<\/em>&nbsp;has a variable address, or shares its address (via NAT or something similar) with hosts you do not trust, omit the &#8216;from=&#8221;10.1.1.1&#8243;,&#8217; part of the line (including the comma), but leave the &#8216;command&#8217; portion. This way, only the &#8216;rsync&#8217; will be possible from connections using this key. Make&nbsp;<strong>certain<\/strong>&nbsp;that the &#8216;validate-rsync&#8217; script is executable by&nbsp;<em>remoteuser<\/em>&nbsp;on&nbsp;<em>remotehost<\/em>&nbsp;and test it.<\/div>\n<div class=\"normal\" style=\"padding-bottom: 10px; padding-right: 10px; font-family: arial, helvetica; font-size: medium;\"><strong>PLEASE NOTE:<\/strong>&nbsp;The private key, though now somewhat limited in what it can do (and hopefully where it can be done from), allows the possessor to copy&nbsp;<strong>any<\/strong>&nbsp;file from&nbsp;<em>remotehost<\/em>&nbsp;that&nbsp;<em>remoteuser<\/em>&nbsp;has access to. This is dangerous, and I should take whatever precautions I deem necessary to maintain the security and secrecy of this key. Some possibilities would be ensuring proper file permissions are assigned, consider using a key caching daemon, and consider if I really need this process automated verses the risk.<\/div>\n<div class=\"normal\" style=\"padding-bottom: 10px; padding-right: 10px; font-family: arial, helvetica; font-size: medium;\"><strong>ALSO NOTE:<\/strong>&nbsp;Another security detail to consider is the SSH daemon configuration on&nbsp;<em>remotehost<\/em>. This example focuses on a user (<em>remoteuser<\/em>) who is not&nbsp;<em>root<\/em>. I recommend not using&nbsp;<em>root<\/em>&nbsp;as the remote user because<em>root<\/em>&nbsp;has access to every file on&nbsp;<em>remotehost<\/em>. That capability alone is very dangerous, and the penalties for a mistake or misconfiguration can be far steeper than those for a &#8216;normal&#8217; user. If you do not use&nbsp;<em>root<\/em>&nbsp;as your remote user (ever), and you make security decisions for&nbsp;<em>remotehost<\/em>, I recommend either:<\/p>\n<div class=\"console\" style=\"font-family: courier, times; font-size: 13px; margin: 10px 30px; padding: 10px; border: 2px solid black;\">PermitRootLogin no&nbsp;<\/div>\n<p>or:<\/p>\n<div class=\"console\" style=\"font-family: courier, times; font-size: 13px; margin: 10px 30px; padding: 10px; border: 2px solid black;\">PermitRootLogin forced-commands-only&nbsp;<\/div>\n<p>be included in the &#8216;\/etc\/ssh\/sshd_config&#8217; file on&nbsp;<em>remotehost<\/em>. These are global settings, not just related to this connection, so be sure you do not need the capability these configuration options prohibit.&nbsp;<a style=\"color: #000077; text-decoration: none; background-color: transparent;\" name=\"ref8\" href=\"http:\/\/troy.jdmz.net\/rsync\/index.html#note8\">[8]<\/a>.<\/div>\n<div class=\"normal\" style=\"padding-bottom: 10px; padding-right: 10px; font-family: arial, helvetica; font-size: medium;\">The &#8216;AllowUsers&#8217;, &#8216;AllowGroups&#8217;, &#8216;DenyUsers&#8217;, and &#8216;DenyGroups&#8217; key words can be used to restrict SSH access to particular users and groups. They are documented in the man page for &#8220;sshd_config&#8221;, but I will mention that they all can use &#8216;*&#8217; and &#8216;?&#8217; as wildcards to allow and deny access to users and groups that match patterns. &#8216;AllowUsers&#8217; and &#8216;DenyUsers&#8217; can also restrict by host when the pattern is in USER@HOST form.<\/div>\n<div class=\"normal\" style=\"padding-bottom: 10px; padding-right: 10px; font-family: arial, helvetica; font-size: medium;\">\n<div class=\"secondary-heading\" style=\"font-size: 24px;\">Troubleshooting<\/div>\n<p>Now that I have the key with no password in place and configured, I need to test it out before putting it in a cron job (which has its own small set of baggage). I exit from the ssh session to&nbsp;<em>remotehost<\/em>&nbsp;and try&nbsp;<a style=\"color: #000077; text-decoration: none; background-color: transparent;\" name=\"ref9\" href=\"http:\/\/troy.jdmz.net\/rsync\/index.html#note9\">[9]<\/a>:<\/p>\n<div class=\"console\" style=\"font-family: courier, times; font-size: 13px; margin: 10px 30px; padding: 10px; border: 2px solid black;\">$ rsync -avz -e &#8220;ssh -i \/home\/thisuser\/cron\/thishost-rsync-key&#8221; remoteuser@remotehost:\/remote\/dir \/this\/dir\/<\/div>\n<p>If this doesn&#8217;t work, I will take off the &#8220;command&#8221; restriction on the key and try again. If it asks for a password, I will check permissions on the private key file (on&nbsp;<em>thishost<\/em>, should be 600), on &#8216;authorized_keys&#8217; and (on<em>remotehost<\/em>, should be 600), on the &#8216;~\/.ssh\/&#8217; directory (on both hosts, should be 700), and on the home directory (&#8216;~\/&#8217;) itself (on both hosts, should not be writeable by anyone but the user). If some cryptic &#8216;rsync&#8217; protocol error occurs mentioning the &#8216;validate-rsync&#8217; script, I will make sure the permissions on &#8216;validate-rsync&#8217; (on&nbsp;<em>remotehost<\/em>, may be 755 if every&nbsp;<em>remotehost<\/em>&nbsp;user is trusted) allow&nbsp;<em>remoteuser<\/em>&nbsp;to read and execute it.<\/div>\n<div class=\"normal\" style=\"padding-bottom: 10px; padding-right: 10px; font-family: arial, helvetica; font-size: medium;\">If things still aren&#8217;t working out, some useful information may be found in log files. Log files usually found in the&nbsp;<strong>\/var\/log\/<\/strong>&nbsp;directory on most linux hosts, and in the&nbsp;<strong>\/var\/log\/secure<\/strong>&nbsp;log file on Red Hat-ish linux hosts. The most useful logfiles in this instance will be found on&nbsp;<em>remotehost<\/em>, but&nbsp;<em>localhost<\/em>&nbsp;may provide some client side information in its logs&nbsp;<a style=\"color: #000077; text-decoration: none; background-color: transparent;\" name=\"ref10\" href=\"http:\/\/troy.jdmz.net\/rsync\/index.html#note10\">[10]<\/a>&nbsp;. If you can&#8217;t get to the logs, or are just impatient, you can tell the &#8216;ssh&#8217; executable to provide some logging with the &#8216;verbose&#8217; commands: &#8216;-v&#8217;, &#8216;-vv&#8217;, &#8216;-vvv&#8217;. The more v&#8217;s, the more verbose the output. One is in the command above, but the one below should provide much more output:<\/p>\n<div class=\"console\" style=\"font-family: courier, times; font-size: 13px; margin: 10px 30px; padding: 10px; border: 2px solid black;\">$ rsync -avvvz -e &#8220;ssh -i \/home\/thisuser\/cron\/thishost-rsync-key&#8221; remoteuser@remotehost:\/remote\/dir \/this\/dir\/&nbsp;<\/div>\n<p>Hopefully, it will always just work flawlessly so I never have to extend the troubleshooting information listed here&nbsp;<a style=\"color: #000077; text-decoration: none; background-color: transparent;\" name=\"ref11\" href=\"http:\/\/troy.jdmz.net\/rsync\/index.html#note11\">[11]<\/a>&nbsp;.<\/div>\n<div class=\"normal\" style=\"padding-bottom: 10px; padding-right: 10px; font-family: arial, helvetica; font-size: medium;\">\n<div class=\"secondary-heading\" style=\"font-size: 24px;\">Cron Job Setup<\/div>\n<p>The last step is the cron script. I use something like this:<\/p>\n<div class=\"console\" style=\"font-family: courier, times; font-size: 13px; margin: 10px 30px; padding: 10px; border: 2px solid black;\">#!\/bin\/sh&nbsp;<\/p>\n<p>RSYNC=\/usr\/bin\/rsync&nbsp;<br \/>SSH=\/usr\/bin\/ssh&nbsp;<br \/>KEY=\/home\/thisuser\/cron\/thishost-rsync-key&nbsp;<br \/>RUSER=remoteuser&nbsp;<br \/>RHOST=remotehost&nbsp;<br \/>RPATH=\/remote\/dir&nbsp;<br \/>LPATH=\/this\/dir\/&nbsp;<\/p>\n<p>$RSYNC -az -e &#8220;$SSH -i $KEY&#8221; $RUSER@$RHOST:$RPATH $LPATH&nbsp;<\/p><\/div>\n<p>because it is easy to modify the bits and pieces of the command line for different hosts and paths. I will usually call it something like &#8216;rsync-remotehost-backups&#8217; if it contains backups. I test the script too, just in case I carefully inserted an error somewhere.<\/p><\/div>\n<div class=\"normal\" style=\"padding-bottom: 10px; padding-right: 10px; font-family: arial, helvetica; font-size: medium;\">When I get the script running successfully, I use &#8216;crontab -e&#8217; to insert a line for this new cron job:<\/p>\n<div class=\"console\" style=\"font-family: courier, times; font-size: 13px; margin: 10px 30px; padding: 10px; border: 2px solid black;\">0 5 * * * \/home\/thisuser\/cron\/rsync-remotehost-backups&nbsp;<\/div>\n<p>for a daily 5 AM sync, or:<\/p>\n<div class=\"console\" style=\"font-family: courier, times; font-size: 13px; margin: 10px 30px; padding: 10px; border: 2px solid black;\">0 5 * * 5 \/home\/thisuser\/cron\/rsync-remotehost-backups&nbsp;<\/div>\n<p>for a weekly (5 AM on Fridays). Monthly and yearly ones are rarer for me, so look at &#8220;man crontab&#8221; or&nbsp;<a style=\"color: #000077; text-decoration: none; background-color: transparent;\" href=\"http:\/\/troy.jdmz.net\/cron\/\">here<\/a>&nbsp;for advice on those.<\/div>\n<p><br style=\"font-family: arial, helvetica; font-size: medium;\" \/><\/p>\n<div class=\"normal\" style=\"padding-bottom: 10px; padding-right: 10px; font-family: arial, helvetica; font-size: medium;\">Alright! Except for the everyday &#8220;keeping up with patches&#8221; thing, the insidious &#8220;hidden configuration flaws&#8221; part, and the unforgettable &#8220;total failure of human logic&#8221; set of problems, my work here is done. Enjoy!<\/div>\n","protected":false},"excerpt":{"rendered":"<p>This document covers using cron, ssh, and rsync to backup files over a local network or the Internet. Part of my goal is to ensure no user intervention is required when the computer is restarted (for passwords, keys, or key managers). I like to backup some logging, mail, and configuration information sometimes on hosts across [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[33],"tags":[],"class_list":["post-337","post","type-post","status-publish","format-standard","hentry","category-centos-6"],"_links":{"self":[{"href":"https:\/\/shan.info\/new\/wp-json\/wp\/v2\/posts\/337","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/shan.info\/new\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/shan.info\/new\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/shan.info\/new\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/shan.info\/new\/wp-json\/wp\/v2\/comments?post=337"}],"version-history":[{"count":0,"href":"https:\/\/shan.info\/new\/wp-json\/wp\/v2\/posts\/337\/revisions"}],"wp:attachment":[{"href":"https:\/\/shan.info\/new\/wp-json\/wp\/v2\/media?parent=337"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/shan.info\/new\/wp-json\/wp\/v2\/categories?post=337"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/shan.info\/new\/wp-json\/wp\/v2\/tags?post=337"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}