{"id":747,"date":"2014-02-21T19:54:02","date_gmt":"2014-02-21T18:54:02","guid":{"rendered":"http:\/\/www.jbahillo.com\/?p=747"},"modified":"2014-02-21T22:18:48","modified_gmt":"2014-02-21T21:18:48","slug":"syncing-zentyal-ca-between-two-zentyal-servers","status":"publish","type":"post","link":"https:\/\/www.jbahillo.com\/?p=747","title":{"rendered":"Syncing Zentyal CA between two Zentyal servers"},"content":{"rendered":"<p>This document describes the procedure to set up CA sync between two Zentyal servers. We will use for this rsync being run in a cron job.<br \/>\nWe will use root in the side that starts the connection (provided script will be run by cron) and ebox for the side that receives it. We could use any other user, but using user ebox avoid having to create extra unneeded configurations. For the sake of the example we&#8217;ll be referring to two servers here:<\/p>\n<ol>\n<li>(Server A) The server on which the CA existed previously, and from which the files for the CA will be taken.<\/li>\n<li>(Server B). The secondary server to which we want to export the CA which exists on Server A.<\/li>\n<\/ol>\n<p>In order to better understand the procedure we must keep in mind that:<br \/>\nZentyal CA files are stored on \/var\/lib\/zentyal\/CA<br \/>\nThis folder has these permissions:<\/p>\n<pre class=\"brush: bash; gutter: true\">drwx r-x --x 9 ebox ebox<\/pre>\n<p>ebox user has as his home the folder \/var\/lib\/zentyal\/<\/p>\n<ul>\n<li>With this information, we&#8217;ll proceed to follow these steps:Check that rsync is installed in server B, and if not install it.<\/li>\n<\/ul>\n<pre class=\"brush: bash; gutter: true\"> sudo apt-get install rsync<\/pre>\n<ul>\n<li>Check if root has a rsa key in server B. If it did not have, create if with ssh-keygen<\/li>\n<\/ul>\n<pre class=\"brush: bash; gutter: true\"> if [ ! -f \/root\/.ssh\/id_rsa.pub ] ; then \/usr\/bin\/ssh-keygen&quot; ; else echo &quot;Key Already exists&quot; ; fi<\/pre>\n<p>&nbsp;<\/p>\n<ul>\n<li>Create folder \/var\/lib\/zentyal\/.ssh\/ and create file authorized_keys<\/li>\n<\/ul>\n<pre class=\"brush: bash; gutter: true\">sudo mkdir -p \/var\/lib\/zentyal\/.ssh\/\r\nsudo touch \/var\/lib\/zentyal\/.ssh\/authorized_keys<\/pre>\n<ul>\n<li>Chown both to ebox.ebox:<\/li>\n<\/ul>\n<pre class=\"brush: bash; gutter: true\">sudo chown -R ebox.ebox \/var\/lib\/zentyal\/.ssh\/<\/pre>\n<ul>\n<li>Copy the root public key to \/var\/lib\/zentyal\/.ssh\/authorized_keys of server A. Given ebox user has no password you will have to do it by hand, as long as you won&#8217;t be able to do it with ssh-copy-id . Thus, open \/root\/.ssh\/id_rsa.pub and paste its contents into \/var\/lib\/zentyal\/.ssh\/authorized_keys of server A.<\/li>\n<\/ul>\n<ul>\n<li>Test that you can ssh without using password from root as ebox user:<\/li>\n<\/ul>\n<pre class=\"brush: actionscript3; gutter: true\">sudo ssh ebox@SERVER-A-IP<\/pre>\n<ul>\n<li>Now you can:<\/li>\n<\/ul>\n<p style=\"padding-left: 60px;\">1. Limit connections from IP:<\/p>\n<p style=\"padding-left: 90px;\">To do so edit in SERVER A \/var\/lib\/zentyal\/.ssh\/authorized_keys, and add prior to the ssh-rsa this:<\/p>\n<pre class=\"brush: bash; gutter: true\">from=&quot;SERVER-B-IP&quot; ssh-rsa dasghgdgh+RqUVx5wzgnaMxH2Km5KRx0Wzvsa5YvxjwERVVXs2mUEes5mDpoDMX9pUAwKqPCS5C\r\nLyDwI+t0xNmVzPzeZjhypIfvBmgaG7pBNx7Zted7C+fha1X3SUmT4TguLzy7pfWbG7CKr2XkkFUYUOdUniYc99NsIxY1\/51+\/jjhfg\r\njhfg\/Pr5jqH+jhfjfgj\/jhfgjh+9kErROS1z root@hostname<\/pre>\n<p style=\"padding-left: 60px;\">2.\u00a0 Ensuring that only rsync is used for this ssh connection:<br \/>\nTo do so edit in SERVER A \/var\/lib\/zentyal\/.ssh\/authorized_keys, and add prior to the ssh-rsa this:<\/p>\n<pre class=\"brush: bash; gutter: true\">command=&quot;\/usr\/share\/bin\/check_command.sh\u201d ssh-rsa fdasghgdgh+RqUVx5wzgnaMxH2Km5KRx0Wzvsa5YvxjwERV\r\nVXs2mUEes5mDpoDMX9pUAwKqPCS5CLyDwI+t0xNmVzPzeZjhypIfvBmgaG7pBNx7Zted7C+fha1X3SUmT4TguLzy7pfWbG7CKr\r\n2XkkFUYUOdUniYc99NsIxY1\/51+\/jjhfgjhfg\/Pr5jqH+jhfjfgj\/jhfgjh+9kErROS1z root@hostname<\/pre>\n<p style=\"padding-left: 60px;\">Now, you must add the script it mentions this line (script taken from http:\/\/troy.jdmz.net\/rsync\/index.html)<\/p>\n<pre class=\"brush: bash; gutter: true\">#!\/bin\/sh\r\n\r\ncase &quot;$SSH_ORIGINAL_COMMAND&quot; in\r\n*\\&amp;*)\r\necho &quot;Rejected&quot;\r\n;;\r\n*\\(*)\r\necho &quot;Rejected&quot;\r\n;;\r\n*\\{*)\r\necho &quot;Rejected&quot;\r\n;;\r\n*\\;*)\r\necho &quot;Rejected&quot;\r\n;;\r\n*\\&lt;*)\r\necho &quot;Rejected&quot;\r\n;;\r\n*\\`*)\r\necho &quot;Rejected&quot;\r\n;;\r\n*\\|*)\r\necho &quot;Rejected&quot;\r\n;;\r\nrsync\\ --server*)\r\n$SSH_ORIGINAL_COMMAND\r\n;;\r\n*)\r\necho &quot;Rejected&quot;\r\n;;\r\nesac<\/pre>\n<p style=\"padding-left: 60px;\">If you use both, separate them with a \u201c,\u201d:<\/p>\n<pre class=\"brush: bash; gutter: true\">from=&quot;SERVER-B-IP&quot;,command=&quot;\/usr\/share\/bin\/check_command.sh\u201d ssh-rsa fdasghgdgh+RqUVx5wzgnaMxH2Km5KRx0Wzvsa5Y\r\nvxjwERVVXs2mUEes5mDpoDMX9pUAwKqPCS5CLyDwI+t0xNmVzPzeZjhypIfvBmgaG7pBNx7Zted7C+fha1X3SUmT4TguLzy7pfWbG7CKr2Xkk\r\nFUYUOdUniYc99NsIxY1\/51+\/jjhfgjhfg\/Pr5jqH+jhfjfgj\/jhfgjh+9kErROS1z root@hostname<\/pre>\n<p>&nbsp;<\/p>\n<ul>\n<li>Create the folder where you&#8217;re going to store the script that will do the sync and give it appropriate permissions:<\/li>\n<\/ul>\n<pre class=\"brush: bash; gutter: true\">mkdir \/var\/local\/rsync-ca\r\nchmod 754 \/var\/local\/rsync-ca<\/pre>\n<p>&nbsp;<\/p>\n<ul>\n<li>Create the script file and give it proper permissions:<\/li>\n<\/ul>\n<pre class=\"brush: bash; gutter: true\"> chmod 740 \/var\/local\/sync-ca\/rsync-ca<\/pre>\n<p>&nbsp;<\/p>\n<ul>\n<li>Place the following content on the script (change variables as needed)<\/li>\n<\/ul>\n<pre class=\"brush: bash; gutter: true\">#!\/bin\/bash\r\nRSYNC=\/usr\/bin\/rsync\r\nSSH=\/usr\/bin\/ssh\r\nKEY=\/root\/.ssh\/id_rsa\r\nRUSER=ebox\r\nRHOST=SERVER-A-IP\r\nRPATH=\/var\/lib\/zentyal\/CA\r\nLPATH=\/var\/lib\/zentyal\/\r\n$RSYNC -az -e &quot;$SSH -i $KEY&quot; $RUSER@$RHOST:$RPATH $LPATH<\/pre>\n<p>&nbsp;<\/p>\n<ul>\n<li>Test the script and confirm that it works as expected<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul>\n<li>Create the cron job for the script we have just created. For instance, to run this daily write under \/etc\/cron.d\/rsync-ca :<\/li>\n<\/ul>\n<pre class=\"brush: bash; gutter: true\"> # \/etc\/cron.d\/rsync-ca - Runs the script that syncs CA with SERVERA daily\r\n\r\nSHELL=\/bin\/sh\r\nPATH=\/usr\/bin:\/bin\r\n\r\n# Log data for report hourly\r\n@daily root \/var\/local\/rsync-ca\/rsync-ca<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This document describes the procedure to set up CA sync between two Zentyal servers. We will use for this rsync being run in a cron job. We will use root in the side that starts the connection (provided script will&hellip;<\/p>\n<p class=\"more-link-p\"><a class=\"more-link\" href=\"https:\/\/www.jbahillo.com\/?p=747\">Read more &rarr;<\/a><\/p>\n","protected":false},"author":21,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"ep_exclude_from_search":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[10,96,124],"tags":[],"class_list":["post-747","post","type-post","status-publish","format-standard","hentry","category-gnulinux","category-zentyal","category-zentyal-world"],"aioseo_notices":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p74T96-c3","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.jbahillo.com\/index.php?rest_route=\/wp\/v2\/posts\/747","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jbahillo.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jbahillo.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jbahillo.com\/index.php?rest_route=\/wp\/v2\/users\/21"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jbahillo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=747"}],"version-history":[{"count":6,"href":"https:\/\/www.jbahillo.com\/index.php?rest_route=\/wp\/v2\/posts\/747\/revisions"}],"predecessor-version":[{"id":753,"href":"https:\/\/www.jbahillo.com\/index.php?rest_route=\/wp\/v2\/posts\/747\/revisions\/753"}],"wp:attachment":[{"href":"https:\/\/www.jbahillo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=747"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jbahillo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=747"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jbahillo.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=747"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}