Tuesday, 2 January 2024

How to Use Git Version Control System in Linux

 Version Control (revision control or source control) is a way of recording changes to a file or collection of files over time so that you can recall specific versions later. A version control system (or VCS in short) is a tool that records changes to files on a filesystem.

There are many version control systems out there, but Git is currently the most popular and frequently used, especially for source code management. Version control can actually be used for nearly any type of file on a computer, not only source code.

Version control systems/tools offer several features that allow individuals or a group of people to:

  • create versions of a project.
  • track changes accurately and resolve conflicts.
  • merge changes into a common version.
  • rollback and undo changes to selected files or an entire project.
  • access historical versions of a project to compare changes over time.
  • see who last modified something that might be causing a problem.
  • create a secure offsite backup of a project.
  • use multiple machines to work on a single project and so much more.

A project under a version control system such as Git will have mainly three sections, namely:

  • a repository: a database for recording the state of or changes to your project files. It contains all of the necessary Git metadata and objects for the new project. Note that this is normally what is copied when you clone a repository from another computer on a network or remote server.
  • a working directory or area: stores a copy of the project files which you can work on (make additions, deletions and other modification actions).
  • a staging area: a file (known as index under Git) within the Git directory, that stores information about changes, that you are ready to commit (save the state of a file or set of files) to the repository.

There are two main types of VCSs, with the main difference being the number of repositories:

  • Centralized Version Control Systems (CVCSs): here each project team member gets their own local working directory, however, they commit changes to just a single central repository.
  • Distributed Version Control Systems (DVCSs): under this, each project team member gets their own local working directory and Git directory where they can make commits. After an individual makes a commit locally, other team members can’t access the changes until he/she pushes them to the central repository. Git is an example of a DVCS.

In addition, a Git repository can be bare (repository that doesn’t have a working directory) or non-bare (one with a working directory). Shared (or public or central) repositories should always be bare – all Github repositories are bare.

Learn Version Control with Git

Git is a free and open source, fast, powerful, distributed, easy to use, and popular version control system that is very efficient with large projects, and has a remarkable branching and merging system. It is designed to handle data more like a series of snapshots of a mini filesystem, which is stored in a Git directory.

The workflow under Git is very simple: you make modifications to files in your working directory, then selectively add just those files that have changed, to the staging area, to be part of your next commit.

Once you are ready, you do a commit, which takes the files from staging area and saves that snapshot permanently to the Git directory.

To install Git in Linux, use the appropriate command for your distribution of choice:

$ sudo apt install git   [On Debian/Ubuntu]
$ sudo yum install git   [On CentOS/RHEL]

After installing Git, it is recommended that you tell Git who you are by providing your full name and email address, as follows:

$ git config --global user.name “Aaron Kili”
$ git config --global user.email “aaronkilik@gmail.com”

To check your Git settings, use the following command.

$ git config --list 
View Git Settings
View Git Settings

Creates a New Git Repository

Shared repositories or centralized workflows are very common and that is what we will demonstrate here. For example, we assume that you have been tasked to setup a remote central repository for system administrators/programmers from various departments in your organization, to work on a project called bashscripts, which will be stored under /projects/scritpts/ on the server.

SSH into the remote server and create the necessary directory, create a group called sysadmins (add all project team members to this group e.g user admin), and set the appropriate permissions on this directory.

# mkdir-p /projects/scripts/
# groupadd sysadmins
# usermod -aG sysadmins admin
# chown :sysadmins -R /projects/scripts/
# chmod 770 -R /projects/scripts/

Then initialize a bare project repository.

# git init --bare /projects/scripts/bashscripts
Initialize Git Shared Repository
Initialize Git Shared Repository

At this point, you have successfully initialized a bare Git directory which is the central storage facility for the project. Try to do a listing of the directory to see all the files and directories in there:

# ls -la /projects/scripts/bashscripts/
List Git Shared Repository
List Git Shared Repository

Clone a Git Repository

Now clone the remote shared Git repository to your local computer via SSH (you can also clone via HTTP/HTTPS if you have a web server installed and appropriately configured, as is the case with most public repositories on Github), for example:

$ git clone ssh://admin@remote_server_ip:/projects/scripts/bashscripts 

To clone it to a specific directory (~/bin/bashscripts), use the command below.

$ git clone ssh://admin@remote_server_ip:/projects/scripts/bashscripts ~/bin/bashscripts
Clone Shared Git Repository to Local
Clone Shared Git Repository to Local

You now have a local instance of the project in a non-bare repository (with a working directory), you can create the initial structure of the project (i.e add a README.md file, sub-directories for different categories of scripts e.g recon to store reconnaissance scripts, sysadmin ro store sysadmin scripts etc.):

$ cd ~/bin/bashscripts/
$ ls -la
Create Git Project Structure
Create Git Project Structure

Check a Git Status Summary

To display the status of your working directory, use the status command which will shows you any changes you have made; which files are not being tracked by Git; those changes that have been staged and so on.

$ git status 
Check Git Status
Check Git Status

Git Stage Changes and Commit

Next, stage all the changes using the add command with the -A switch and do the initial commit. The -a flag instructs the command to automatically stage files that have been modified, and -m is used to specify a commit message:

$ git add -A
$ git commit -a -m "Initial Commit"
Do Git Commit
Do Git Commit

Publish Local Commits to Remote Git Repository

As the project team lead, now that you have created the project structure, you can publish the changes to the central repository using the push command as shown.

$ git push origin master
Push Commit to Centrol Git Repository
Push Commit to Centrol Git Repository

Right now, your local git repository should be up-to-date with the project central repository (origin), you can confirm this by running the status command once more.

$ git status
Check Git Status
Check Git Status

You can also inform you colleagues to start working on the project by cloning the repository to their local computers.

Create a New Git Branch

Branching allows you to work on a feature of your project or fix issues quickly without touching the codebase (master branch). To create a new branch and then switch to it, use the branch and checkout commands respectively.

$ git branch latest
$ git checkout latest

Alternatively, you can create a new branch and switch to it in one step using the checkout command with the -b flag.

$ git checkout -b latest

You can also create a new branch based on another branch, for instance.

$ git checkout -b latest master

To check which branch you are in, use branch command (an asterisk character indicates the active branch):

$ git branch
Check Active Branch
Check Active Branch

After creating and switching to the new branch, make some changes under it and do some commits.

$ vim sysadmin/topprocs.sh
$ git status
$ git commit add  sysadmin/topprocs.sh
$ git commit -a -m 'modified topprocs.sh'

Merge Changes From One Branch to Another

To merge the changes under the branch test into the master branch, switch to the master branch and do the merge.

$ git checkout master 
$ git merge test 
Merge Test Branch into Master
Merge Test Branch into Master

If you no longer need a particular branch, you can delete it using the -d switch.

$ git branch -d test

Download Changes From Remote Central Repository

Assuming your team members have pushed changes to the central project repository, you can download any changes to your local instance of the project using the pull command.

$ git pull origin
OR
$ git pull origin master	#if you have switched to another branch
Pull Changes from Central Repository
Pull Changes from Central Repository

Inspect Git Repository and Perform Comparisons

In this last section, we will cover some useful Git features that keep track of all activities that happened in your repository, thus enabling you to view the project history.

The first feature is Git log, which displays commit logs:

$ git log
View Git Commit Logs
View Git Commit Logs

Another important feature is the show command which displays various types of objects (such as commits, tags, trees etc..):

$ git show
Git Show Objects
Git Show Objects

The third vital feature you need to know is the diff command, used to compare or show difference between branches, display changes between the working directory and the index, changes between two files on disk and so much more.

For instance to show the difference between the master and latest branch, you can run the following command.

$ git diff master latest
Show Difference Between Branches
Show Difference Between Branches

Summary

Git allows a team of people to work together using the same file(s), while recording changes to the file(s) over time so that they can recall specific versions later.

This way, you can use Git for managing source code, configuration files or any file stored on a computer. You may want to refer to the Git Online Documentation for further documentation.

How to Install Git on CentOS 8

 Version Control System tool plays a vital role in today’s modern Software development. Version control is a software that helps a group of software developers work together and manage the history of the work. It does not overwrite other’s changes, therefore you can keep track of every change, revert the file or a project to its previous state.

The version control tool helps you to recover the lost file very easily. If a mistake is made by anyone from the team, one can look back and compare the earlier version of the file and fix the mistake or any conflict.

Git is one of the most popular decentralized version control tools used by developers to coordinate the work amongst them. It was designed by Linus Torvalds ( the creator of Linux Kernel.) in the year 2005.

Git offers features like data assurance, workflows, create branches, revert to the previous stage, incredible speed, keep track of your code changes, view logs, and many more. It allows you to perform your work in offline mode and when ready, you need the internet connection to publish the changes and take the latest changes.

In this tutorial, we will explain to you how to install Git on a CentOS 8 server using yum and source code. Each installation has its own benefits, the choice is up to you.

For example, users who want to Perpetuate Git update will use the yum method and those who need features by a particular version of Git will use the source code method.

Important: You must have a CentOS 8 server installed and configured with a sudo user with root privileges. If you don’t have one, you can create a sudo account

Installing Git with Yum on CentOS 8

One of the simplest and easiest ways to install Git is with a yum package manager, but the available version may be older than the newest version available. If you want to install the newest release of Git, consider compiling it from source (instructions for compiling Git from the source given further down below).

$ sudo yum install git

Once installed git, you can verify the version of installed Git using the following command.

$ git --version

git version 2.18.1

Installing Git from Source Code

If you want to feature by a specific version of Git or need flexibility in installation then one of the best methods is to gather the software Git from Source. However, it will not manage and update Git installation through the yum package manager but will allow you to install the latest version of Git and customize the build options. This method is a bit lengthy process.

Before we move forward with the installation, you will need the following necessary tools to build the binary from the source.

$ sudo yum groupinstall "Development Tools"
$ sudo yum install wget unzip gettext-devel openssl-devel perl-CPAN perl-devel zlib-devel libcurl-devel expat-devel

Once the tools are installed successfully, open any browser and visit Gits project’s mirror on GitHub Release. The one at the top is the latest version of Git, but it may vary at your end. Now, look at the version you require then right-click the source code (tar.gz) and copy the link to download using following wget command as shown.

$ sudo wget https://github.com/git/git/archive/v2.23.0.tar.gz -O git.tar.gz

Once the download is completed unzip the source package using tar command, now move into the directory.

$ sudo tar -xf git.tar.gz
$ cd git-*

Now install and build Git from source using the following command.

$ sudo make prefix=/usr/local all install

Once compilation finishes, you can type the following command to verify the Git Version installation.

$ git --version

git version 2.23.0

Configuring Git

Now git is installed on the CentOS machine successfully, now you will need to set up your personal info which will be used when you commit any changes to your code.

$ git config --global user.name "Your Name"
$ git config --global user.email "youremail@yourdomain.com"

To verify that the above settings were added successfully, you can list all of the configuration settings that have been added by typing.

$ git config --list

user.name=Your Name
user.email=youremail@yourdomain.com

The above settings are stored in the global configuration ~/.gitconfig file. To make any additional changes to this file, use git config command or edit the file manually.

Monday, 11 December 2023

Cisco Command lines

 


Commands in MikroTik Router OS



Basic commands for Mikrotik Router OS – It is definitely confusing for those of you who are just learning to use Mikrotik with the command (command line) used in Router OS. Whereas, many basic commands of Mikrotik are important to be known so that user will utilize the Router OS well. Actually, the basic commands of  MikroTik Router OS have not much different from
the basic commands in Linux in general. Because, the Mikrotik is actually an outgrowth of the Debian linux kernel.


Router OS mikrotik shell commands is just the same as Linux’s, like efficient in writing the command; imply use the TAB key on the keyboard to make a long command; no longer need to be typed; simply type the initial command, then Shell will automatically display the complete commands. For example, the IP ADDRESS commands on mikrotik. It is simply type the IP ADD, then press spacebar and press the TAB key, then the shell will automatically recognize and translate the IP ADDRESS command.

Here are the basic commands of Mikrotik that are commonly used:

1 . Commands to shutdown and restart the computer, type:
[ admin @ MikroTik ] > system shutdown (to shutdown the computer)
[ admin @ MikroTik ] > system reboot (to restart the computer)
[ admin @ MikroTik ] > system reset ( to reset  predefined configuration). Please keep in mind that the commands should be performed on the admin directory.

2 . Commands to change the name of the Mikrotik machine, type:
[ admin @ MikroTik ] > /system identity
[ admin @ MikroTik ] > system identity> set name = proxy
To view the configuration, type "print" or "pr"
E.g. [ admin @ MikroTik ] system identity > pr name: " proxy "
Then the console will turn into [ admin @ proxy ]

3 . Commands to change the password of MikroTik machine, type:
[ admin @ proxy ] > /password
[ admin @ proxy ] password > old password (if you have not set a password then enter empty)
[admin @ proxy ] password > new password : ...... (type the new password)
[admin @ proxy ] password > Retype new password : ........ (insert once again password)

For example:
If the old password is empty and the new password is ABCD, then the command is as follows:
[ admin @ proxy ] > /password
[ admin @ proxy ] password > old password
[ admin @ proxy ] password > new password ABCD
[ admin @ proxy ] password > Retype new password ABCD

4 . Commands to see the condition of the interface on Mikrotik Router:

[ admin @ MikroTik ] > interface print
Flags : X - disabled , D - dynamic , R - running
# NAME TYPE RX - RATE TX - RATE MTU
0 R ether1 ether 0 0 1500
1 R ether2 ether 0 0 1500
[ admin @ MikroTik ] >

If there is an X interface ( disabled ) after the number ( 0.1 ), then check again
the ethernet card; it should be R (running).

a. Change the interface name
    [admin @ MikroTik ] > interface ( enter)
b . To change the name of Interface ether1 into the Public (or whatever), then:
    [admin @ MikroTik ] interface > set 0 name = Public
c . So does for ether2, it supposed to change the name into Local, then
    [admin @ MikroTik ] interface > set 1 name = Local
d . Or just from the position of the root directory, put the sign " / " , without the quotes
    [admin @ MikroTik ] > /interface set 0 name = Public
e . Check again if the name of the interface has been changed
    [ admin @ MikroTik ] > /interface print
    Flags : X - disabled , D - dynamic , R - running
   # NAME TYPE RX - RATE TX - RATE MTU
   0 R Local ether 0 0 1500
   1 R Public ether 0 0 1500

5 . Commands to see the package software of MikroTik OS :
[ admin @ proxy ] > /system package
[ admin @ proxy ] system package > print or pr> <type

With the command above, then it will appear the package software of MikroTik Os.
For example:

[ admin @ MikroTik system package > pr
Flags : X - disabled
 # Name
0 X routing - test
1 dhcp
2 radiolan
3 user - manager
4 X webproxy - test
5 arlan
6 isdn
7 hotspot -fix
8 ppp
9 wireless
10 web - proxy
11 hotspots
12 advanced -tools
13 security
14 Telephony
15 routing
16, synchronous
17 system
18 routerboard
19 RSTP - bridge - test
20 X wireless- legacy

To see more details, then type:
     [ admin @ proxy ] system package > pr detail fl gs : X - disabled
0 X name = " routing - test" version = " 2.9.27 " build - time = 10:57:53 jul/03/2006 scheduled
1 name = " system " version = " 2.9.27 " build - time = jul/03/2006 10 : 56:37 schedule
2 name = " system " version = " 2.9.27 " build - time = jul/03/2006 10 : 56 : 44 schedule
3 name = " web - proxy " version = " 2.9.27 " build-time = jul/03/2006 10 : ` 58 : 03 schedule
4 name = " advanced - tools" version = " 2.9.27 " build-time = jul / 03 / 2006 10:56 GMT : 41 Scheduled = " "
5 name = " dhcp " version = " 2.9.27 " build-time = 10:56:45 Scheduled jul/03/2006 = " "
6 name = " hotspot " version = " 2.9.27 " build-time = 10:56:58 Scheduled jul/03/2006 = " "
7 x name = " webproxy - test" version = " 2.9.27 " build-time = jul / 03 / 2006 10:57:52 Scheduled
8 name = " routerboard " version = " 2.9.27 " build-time = jul / 03 / 2006 10 : 57 : 17 - [ Q quit | D dump | up | down ]

6 . Commands to upgrade the router software package :
[ admin @ MikroTik ] system upgrade >
To upgrade chosen packages:
Download 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14

7 . Command to enable existing software packages in the MikroTik OS:
    [ admin @ MikroTik ] system page >
     Enable <type package will>
For example :
[ admin @ proxy ] system package > enable dhcp

8 . Command to change the name of Ethernet of the MikroTik OS on the machine:
[ admin @ proxy ] > /interface
[ admin @ proxy ] interfaces > ethernet set Ethernet name = public
Or by using the command
[ admin @ proxy ] interface > set <type number ethernet used>
 name = new ethernet <username> >
For example :
[ admin @ proxy ] interface > set 0 name = public
[ admin @ proxy ] interface > set 1 name = lan
or
[ admin @ proxy ] interface >
set 0 name = public ; set 1 name = lan

9 . Commands to set the IP address on the machine MikroTik OS :
[ admin @ proxy ] > ip address
[ admin @ proxy ] ip address >
Add interface = <username> interface> address =
( type the IP address /subnet mask interface)
example :
If the interface name " Ian " and the IP address that you want: 192.168.01 and subnet mask : 255.255.255.0, then the command are as follows:
[ admin @ proxy ] > /ip address
[ admin @ proxy ] ip address >
Add interface = lan address = 192.168.0.1/24

10 . Commands setting primary and Secondary DNS IP:
[ admin @ proxy ] . /ip dns
[ admin @ proxy ] ip dns >
Set the name - dns > = <IP dns of ISP>

For example :
If IP DNS the primary ISP: 202.134.1.10 and secondary :
202.134.0.0155, then the command are as follows :
[ admin @ proxy ] . /ip dns
[ admin @ proxy ] ip dns >
Set primary - dns = 202.134.1.10
[ admin @ proxy ] ip dns >
Set secondary - dns = 202.134.0.155

11 . Commands to set IP gateway settings on the machine MikroTik OS:
[ admin @ proxy ] > /ip route
[ admin @ proxy ] ip route > add gateway = < ip gateway
Examples of ISP's gateway IP : 202.134.1.1, then the commands are:
[ admin @ proxy ] > /ip route
[ admin @ proxy ] ip route >
add gateway = 202.134.1.1

12 . Commands Translate Network address (NAT) on the MikroTik OS machine
[ admin @ proxy ] > /ip firewall nat
[ admin @ proxy ] ip firewall nat >
add chain = srcnat out-interface = < interface connected
WAN networks > scr-address =
< network-id interface connected to the LAN / subnet mask interface
LAN > action = masquerade

For example :
if the LAN interface network - id : "192.168.0.0" and subnet
Mask : " 255.255.255.0 " . for MikroTik OS machine interface that is connected to the network
WAN : " public ", then the command are as follows :
[ admin @ proxy ] > /ip firewall nat
[ admin @ proxy [ ip firewall nat >
Add chain = srcnat out-interface = public
Src-address = 192.168.0.0/24 action = masquerade