Good day my dear Linux Yogi’s,
in today’s illustration I am going to show you how to install and configure etckeeper and to version control your severs /etc directory with local and remote repositories. For this Article it is important that you have read Version Control with GIT and GIT and remote repository at BitBucket since this article is building on top of it.
First things first. Go ahead and create a new Project at BitBucket for your new repository for the server you like to version control the /etc directory.
Next you need to generate a ssh key pair and upload the public ssh key to the remote repository as illustrated it “GIT and remote repository at BitBucket“.
Issue the following command to generate that ssh key pair (make sure you are on an elevated console as root):
# elevate your console to root sudo -s # generate the ssh key pair # -t rsa specifies the encryption # -b 2048 specifies the key strength ssh-keygen -t rsa -b 2048
In the next step you need to copy the public ssh key and paste it into BitBucket.
# Replace <username> with you actual username # for example /home/mchael/.ssh/id_rsa.pub cat /home/<username>/.ssh/id_rsa.pub
copy the entire key string and paste it into BitBucket. The next step is installing etckeeper and git-core by running the following command:
sudo apt-get -y install etckeeper git-core
and then you need to edit the /etc/etckeeper/etckeeper.conf file:
sudo nano /etc/etckeeper/etckeeper.conf
and change the last line from:
Then make sure you are in an elevated console. If you are not sure just execute the following command:
change into the /etc directory:
and execute the following commands to prepare your git:
# Make sure you replace the name and email with yours git config --global user.name "Clark Kent" git config --global user.email firstname.lastname@example.org
After this is done you need to execute the following command to do an initialization of etckeeper and git to the local repository.
!!! You might receive and error message regarding that origin is unknown or not defined. You can ignore it at this stage. !!!
The next command will add the missing remote repository to the configuration:
# Make sure you copy the proper command from BitBucket # for existing project git remote add origin git@gitlab:etckeeper/<servername>.git
and then you can do your initial commit to your local repository with the following command:
etckeeper commit "Initial commit message"
and then you can manually push it out to the remote repository with the following command but etckeeper usually takes care of it as well:
# this will push the changes upstream to the origin from the master git push -u origin master
That is it. If you run apt-get update and apt-get upgrade for example etckeeper will take care if changes been made to the etc directory and commit them automatically to the local and remote repository. If you make changes manually in the etc directory you should always execute the following to commands:
etckeeper commit "Description of your work here" git push -u origin master
!!! Make sure that you are inside thew /etc directory before you run those two commands above. !!!