github - How to sync your server configs with a repository

You can source control the configuration file sin your server.

Let's create a github repository :****/linux-home-svr2.git

We now need to initialise our root directory, but we need to first create a .gitignore file to ignore  all the files apart from the configurations we want to sync with our repository :

tiago@home-svr2:/$ cd /
tiago@home-svr2:/$ sudo apt install git
tiago@home-svr2:/$ sudo touch .gitignore
tiago@home-svr2:/$ sudo vim .gitignore 
tiago@home-svr2:/$ cat .gitignore 
# Exclude all files apart from the congifuration files to sync with the repo.
tiago@home-svr2:/$ sudo touch /root/.ssh/config
tiago@home-svr2:/$ sudo git add .
tiago@home-svr2:/$ sudo git status
On branch master

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)
        new file:   root/.ssh/config

We now need to commit our first file to test the sync :

tiago@home-svr2:/$ git remote add remote-linux-home-svr2****/linux-home-svr2.git
tiago@home-svr2:/$ git remote -v
remote-linux-home-svr2****/linux-home-svr2.git (fetch)
remote-linux-home-svr2****/linux-home-svr2.git (push)

After committing you need to move to the main branch :

  tiago@home-svr2:/$ sudo git branch -M main

Finally we push the changes :

tiago@home-svr2:/$ sudo git push -u remote-linux-home-svr2 main
Username for '': ********
Password for 'https://******': 
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Writing objects: 100% (5/5), 297 bytes | 297.00 KiB/s, done.
Total 5 (delta 0), reused 0 (delta 0)
 * [new branch]      main -> main
Branch 'main' set up to track remote branch 'main' from 'remote-linux-home-svr2'.

Share Tweet Send
You've successfully subscribed to Infoitech - [B]logging
Great! Next, complete checkout for full access to Infoitech - [B]logging
Welcome back! You've successfully signed in
Success! Your account is fully activated, you now have access to all content.