{"id":212,"date":"2017-04-05T11:08:27","date_gmt":"2017-04-05T16:08:27","guid":{"rendered":"http:\/\/etapien.com\/guides\/?p=212"},"modified":"2020-08-24T14:22:20","modified_gmt":"2020-08-24T19:22:20","slug":"add-version-control-linux-etc-directory","status":"publish","type":"post","link":"https:\/\/etapien.com\/guides\/add-version-control-linux-etc-directory\/","title":{"rendered":"How to add version control for your Linux \/etc directory"},"content":{"rendered":"<p>When you think of the Linux \/etc directory, one thing comes to mind: configuration. There&#8217;s a good reason for that; most of your system configuration files are held in this crucial directory. In fact, nearly everything but your user configurations are housed within \/etc, so the importance of this directory cannot be overstated.<\/p>\n<p>That is why it&#8217;s important to monitor the changes that occur within this directory. Having the ability to handle version control of \/etc would make rolling back from a mistake to one of your data center Linux servers significantly easier. Unfortunately, unless your distribution makes use of the btrfs file system, there&#8217;s no real no version control built in. That&#8217;s why tools like etckeeper should be considered must haves.<\/p>\n<p>etckeeper is a set of tools that allows you to keep track of changes to \/etc using a Git, Mercurial, Bazaar, or Darcs repository like you would keep track of changes to a software project. The repository is housed on your local machine (in \/etc\/.git) and is automatically updated once daily.<\/p>\n<p>I will walk you through the installation and usage of etckeeper, using a git repository, on Ubuntu 16.04 Server.<\/p>\n<p>The first thing we must do is install the necessary components.<br \/>\nThis can be done with a single command:<\/p>\n<blockquote><p>sudo apt-get install etckeeper git-core<\/p><\/blockquote>\n<p>Once this is handled, let&#8217;s tell git who we are with the commands:<\/p>\n<p>git config &#8211;global user.name &#8220;YOUR NAME&#8221;<br \/>\n?git config &#8211;global user.email YOUR EMAIL<br \/>\nWhere YOUR NAME is your actual name and YOUR EMAIL is your email address.<\/p>\n<p>Configure etckeeper<br \/>\nThere is only one configuration file for etckeeper, \/etc\/etckeeper\/etckeeper.conf. Open that file for editing and look at the top, where you&#8217;ll see the following:<\/p>\n<p># The VCS to use.<br \/>\n?# VCS=&#8221;hg&#8221;<br \/>\n?VCS=&#8221;git&#8221;<br \/>\n?# VCS=&#8221;bzr&#8221;<br \/>\n?# VCS=&#8221;darcs&#8221;<\/p>\n<p>If the line VCS=&#8221;git&#8221; is commented out, remove the # character and comment out whatever line was uncommented by default (by adding a leading # to the line). That&#8217;s all the change you need to make. Save and close the configuration file.<\/p>\n<p>Initialize etckeeper<br \/>\nNow we must initialize etckeeper. Go back to the terminal window and issue the following command:<\/p>\n<p>sudo etckeeper init<br \/>\nYou should see the following report:<\/p>\n<p>Initialized empty Git repository in \/etc\/.git\/<br \/>\nNext we&#8217;ll run our initial commit with the command:<\/p>\n<p>sudo etckeeper commit &#8220;Initial commit.&#8221;<br \/>\nMake some changes<br \/>\nLet&#8217;s make some changes to the \/etc directory. We&#8217;ll do this by way of an upgrade. Run the following commands:<\/p>\n<p>sudo apt-get update<br \/>\n?sudo apt-get upgrade<br \/>\nOnce those commands complete, issue the command:<\/p>\n<p>sudo git log &#8211;summary -1<br \/>\nYou should see a listing of the changes that occurred to the \/etc directory (Figure A).<\/p>\n<p>Figure A<br \/>\n<a href=\"http:\/\/etapien.com\/guides\/wp-content\/uploads\/2017\/04\/etckeepera.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-213\" src=\"http:\/\/etapien.com\/guides\/wp-content\/uploads\/2017\/04\/etckeepera-300x244.jpg\" alt=\"\" width=\"417\" height=\"339\" srcset=\"https:\/\/etapien.com\/guides\/wp-content\/uploads\/2017\/04\/etckeepera-300x244.jpg 300w, https:\/\/etapien.com\/guides\/wp-content\/uploads\/2017\/04\/etckeepera-624x507.jpg 624w, https:\/\/etapien.com\/guides\/wp-content\/uploads\/2017\/04\/etckeepera.jpg 733w\" sizes=\"(max-width: 417px) 100vw, 417px\" \/><\/a><\/p>\n<p>etckeeper is doing its thing.<\/p>\n<p>What if you make a change to a configuration file? Let&#8217;s change the ServerAdmin option in \/etc\/apache2\/sites-available\/000-default.conf file. Once we&#8217;ve made the change, save and close the file. Now we run the command sudo git status to see the change has been recorded (Figure B).<\/p>\n<p>Figure B<br \/>\n<a href=\"http:\/\/etapien.com\/guides\/wp-content\/uploads\/2017\/04\/etckeeperb.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-214\" src=\"http:\/\/etapien.com\/guides\/wp-content\/uploads\/2017\/04\/etckeeperb-300x87.jpg\" alt=\"\" width=\"410\" height=\"119\" srcset=\"https:\/\/etapien.com\/guides\/wp-content\/uploads\/2017\/04\/etckeeperb-300x87.jpg 300w, https:\/\/etapien.com\/guides\/wp-content\/uploads\/2017\/04\/etckeeperb.jpg 621w\" sizes=\"(max-width: 410px) 100vw, 410px\" \/><\/a><\/p>\n<p>Note: You might notice, that I didn&#8217;t use the sudo command in the images. Because this is a test environment (running as a virtual machine), I first issue the command sudo -s to change to the root user. I don&#8217;t advise doing that on a production machine&#8230;stay out of root.<\/p>\n<p>Finally, we commit the change with the command:<\/p>\n<p>sudo etckeeper commit &#8220;Updated Apache configuration&#8221;<br \/>\nNow if we run sudo git log -1 -p the change will be visible in the log (Figure C).<\/p>\n<p>Figure C<br \/>\n<a href=\"http:\/\/etapien.com\/guides\/wp-content\/uploads\/2017\/04\/etckeeperc.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-215\" src=\"http:\/\/etapien.com\/guides\/wp-content\/uploads\/2017\/04\/etckeeperc-300x135.jpg\" alt=\"\" width=\"407\" height=\"183\" srcset=\"https:\/\/etapien.com\/guides\/wp-content\/uploads\/2017\/04\/etckeeperc-300x135.jpg 300w, https:\/\/etapien.com\/guides\/wp-content\/uploads\/2017\/04\/etckeeperc-768x344.jpg 768w, https:\/\/etapien.com\/guides\/wp-content\/uploads\/2017\/04\/etckeeperc-624x280.jpg 624w, https:\/\/etapien.com\/guides\/wp-content\/uploads\/2017\/04\/etckeeperc.jpg 785w\" sizes=\"(max-width: 407px) 100vw, 407px\" \/><\/a><\/p>\n<p>Revision history at the ready<br \/>\nThat&#8217;s all there is to it. You now have the ability to retain a complete revision history of your \/etc directory. Anyone that has encountered issues with the \/etc directory will understand the importance of having such a system in place. It is important, however, that you run a commit anytime you make a change to \/etc. Yes, etckeeper will do a daily run, but if you want to make those changes easier to find, I highly recommend doing a manual etckeeper commit when you make a change to \/etc.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When you think of the Linux \/etc directory, one thing comes to mind: configuration. There&#8217;s a good reason for that; most of your system configuration files are held in this crucial directory. In fact, nearly everything but your user configurations are housed within \/etc, so the importance of this directory cannot be overstated. That is [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to add version control for your Linux \/etc directory - Tech Howtos<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/etapien.com\/guides\/add-version-control-linux-etc-directory\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to add version control for your Linux \/etc directory - Tech Howtos\" \/>\n<meta property=\"og:description\" content=\"When you think of the Linux \/etc directory, one thing comes to mind: configuration. There&#8217;s a good reason for that; most of your system configuration files are held in this crucial directory. In fact, nearly everything but your user configurations are housed within \/etc, so the importance of this directory cannot be overstated. That is [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/etapien.com\/guides\/add-version-control-linux-etc-directory\/\" \/>\n<meta property=\"og:site_name\" content=\"Tech Howtos\" \/>\n<meta property=\"article:published_time\" content=\"2017-04-05T16:08:27+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-08-24T19:22:20+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/etapien.com\/guides\/wp-content\/uploads\/2017\/04\/etckeepera-300x244.jpg\" \/>\n<meta name=\"author\" content=\"Etapien\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Etapien\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/etapien.com\/guides\/add-version-control-linux-etc-directory\/\",\"url\":\"https:\/\/etapien.com\/guides\/add-version-control-linux-etc-directory\/\",\"name\":\"How to add version control for your Linux \/etc directory - Tech Howtos\",\"isPartOf\":{\"@id\":\"https:\/\/etapien.com\/guides\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/etapien.com\/guides\/add-version-control-linux-etc-directory\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/etapien.com\/guides\/add-version-control-linux-etc-directory\/#primaryimage\"},\"thumbnailUrl\":\"http:\/\/etapien.com\/guides\/wp-content\/uploads\/2017\/04\/etckeepera-300x244.jpg\",\"datePublished\":\"2017-04-05T16:08:27+00:00\",\"dateModified\":\"2020-08-24T19:22:20+00:00\",\"author\":{\"@id\":\"https:\/\/etapien.com\/guides\/#\/schema\/person\/c67f514649b78dbb5ef0c254a0521424\"},\"breadcrumb\":{\"@id\":\"https:\/\/etapien.com\/guides\/add-version-control-linux-etc-directory\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/etapien.com\/guides\/add-version-control-linux-etc-directory\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/etapien.com\/guides\/add-version-control-linux-etc-directory\/#primaryimage\",\"url\":\"http:\/\/etapien.com\/guides\/wp-content\/uploads\/2017\/04\/etckeepera-300x244.jpg\",\"contentUrl\":\"http:\/\/etapien.com\/guides\/wp-content\/uploads\/2017\/04\/etckeepera-300x244.jpg\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/etapien.com\/guides\/add-version-control-linux-etc-directory\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/etapien.com\/guides\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to add version control for your Linux \/etc directory\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/etapien.com\/guides\/#website\",\"url\":\"https:\/\/etapien.com\/guides\/\",\"name\":\"Tech Howtos\",\"description\":\"Tech related useful howtos\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/etapien.com\/guides\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/etapien.com\/guides\/#\/schema\/person\/c67f514649b78dbb5ef0c254a0521424\",\"name\":\"Etapien\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/etapien.com\/guides\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/55021fd8fb4a829ad64ffab0a92d3b90?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/55021fd8fb4a829ad64ffab0a92d3b90?s=96&d=mm&r=g\",\"caption\":\"Etapien\"},\"url\":\"https:\/\/etapien.com\/guides\/author\/Etapien\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to add version control for your Linux \/etc directory - Tech Howtos","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/etapien.com\/guides\/add-version-control-linux-etc-directory\/","og_locale":"en_US","og_type":"article","og_title":"How to add version control for your Linux \/etc directory - Tech Howtos","og_description":"When you think of the Linux \/etc directory, one thing comes to mind: configuration. There&#8217;s a good reason for that; most of your system configuration files are held in this crucial directory. In fact, nearly everything but your user configurations are housed within \/etc, so the importance of this directory cannot be overstated. That is [&hellip;]","og_url":"https:\/\/etapien.com\/guides\/add-version-control-linux-etc-directory\/","og_site_name":"Tech Howtos","article_published_time":"2017-04-05T16:08:27+00:00","article_modified_time":"2020-08-24T19:22:20+00:00","og_image":[{"url":"http:\/\/etapien.com\/guides\/wp-content\/uploads\/2017\/04\/etckeepera-300x244.jpg"}],"author":"Etapien","twitter_misc":{"Written by":"Etapien","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/etapien.com\/guides\/add-version-control-linux-etc-directory\/","url":"https:\/\/etapien.com\/guides\/add-version-control-linux-etc-directory\/","name":"How to add version control for your Linux \/etc directory - Tech Howtos","isPartOf":{"@id":"https:\/\/etapien.com\/guides\/#website"},"primaryImageOfPage":{"@id":"https:\/\/etapien.com\/guides\/add-version-control-linux-etc-directory\/#primaryimage"},"image":{"@id":"https:\/\/etapien.com\/guides\/add-version-control-linux-etc-directory\/#primaryimage"},"thumbnailUrl":"http:\/\/etapien.com\/guides\/wp-content\/uploads\/2017\/04\/etckeepera-300x244.jpg","datePublished":"2017-04-05T16:08:27+00:00","dateModified":"2020-08-24T19:22:20+00:00","author":{"@id":"https:\/\/etapien.com\/guides\/#\/schema\/person\/c67f514649b78dbb5ef0c254a0521424"},"breadcrumb":{"@id":"https:\/\/etapien.com\/guides\/add-version-control-linux-etc-directory\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/etapien.com\/guides\/add-version-control-linux-etc-directory\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/etapien.com\/guides\/add-version-control-linux-etc-directory\/#primaryimage","url":"http:\/\/etapien.com\/guides\/wp-content\/uploads\/2017\/04\/etckeepera-300x244.jpg","contentUrl":"http:\/\/etapien.com\/guides\/wp-content\/uploads\/2017\/04\/etckeepera-300x244.jpg"},{"@type":"BreadcrumbList","@id":"https:\/\/etapien.com\/guides\/add-version-control-linux-etc-directory\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/etapien.com\/guides\/"},{"@type":"ListItem","position":2,"name":"How to add version control for your Linux \/etc directory"}]},{"@type":"WebSite","@id":"https:\/\/etapien.com\/guides\/#website","url":"https:\/\/etapien.com\/guides\/","name":"Tech Howtos","description":"Tech related useful howtos","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/etapien.com\/guides\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/etapien.com\/guides\/#\/schema\/person\/c67f514649b78dbb5ef0c254a0521424","name":"Etapien","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/etapien.com\/guides\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/55021fd8fb4a829ad64ffab0a92d3b90?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/55021fd8fb4a829ad64ffab0a92d3b90?s=96&d=mm&r=g","caption":"Etapien"},"url":"https:\/\/etapien.com\/guides\/author\/Etapien\/"}]}},"_links":{"self":[{"href":"https:\/\/etapien.com\/guides\/wp-json\/wp\/v2\/posts\/212"}],"collection":[{"href":"https:\/\/etapien.com\/guides\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/etapien.com\/guides\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/etapien.com\/guides\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/etapien.com\/guides\/wp-json\/wp\/v2\/comments?post=212"}],"version-history":[{"count":4,"href":"https:\/\/etapien.com\/guides\/wp-json\/wp\/v2\/posts\/212\/revisions"}],"predecessor-version":[{"id":219,"href":"https:\/\/etapien.com\/guides\/wp-json\/wp\/v2\/posts\/212\/revisions\/219"}],"wp:attachment":[{"href":"https:\/\/etapien.com\/guides\/wp-json\/wp\/v2\/media?parent=212"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/etapien.com\/guides\/wp-json\/wp\/v2\/categories?post=212"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/etapien.com\/guides\/wp-json\/wp\/v2\/tags?post=212"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}