What is NTP/SNTP Protocols, How NTP works

What is NTP/SNTP Protocols, How NTP works

The Network Time Protocol is a Networking Protocol which is used to synchronize time for nodes in a Network. NTP is one of the oldest protocol in the TCP/IP stack which is still in use. NTP is intended to synchronize all participating computers to within a few milliseconds of Coordinated Universal Time (UTC).
The protocol is usually described in terms of a client-server model, but can as easily be used in peer-to-peer relationships where both peers consider the other to be a potential time source.

How NTP works

NTP works on IP port – 123 and to run NTP we first install NTP daemon (ntpd) on both Time Provider(server) and Time Consumer(client)

The NTP client initiates a time-request exchange with the NTP server. As a result of this exchange, the client is able to calculate the link delay and its local offset, and adjust its local clock to match the clock at the server’s computer. As a rule, six exchanges over a period of about five to 10 minutes are required to initially set the clock.

Once synchronized, the client updates the clock about once every 10 minutes, which prevents the time drift from happening. In Other words ,large adjustment are made quickly and small adjustment are made over a period of time.

NTP Stratum


NTP uses the concept of stratum to define the hierarchy of NTP servers. At top of the hierarchy are Stratum 1 which gets their time from Atomic clocks which tells exact time at the moment.

Similarly Stratum 2 time providers get their time from Stratum 1 time provider and Stratum 3 from Stratum 2. And these stratum can go upto 256 layers.

There are many Stratum 2 servers available on the public internet which we can use for couple of PC. But if you have large number of PC’s in the network it is wise to create a local stratum (maybe 2-3) which get its time from Stratum 2 time provider and PC’s in your local network can get time from its local Stratum.

Some important terms related to NTP

Stepping: When time difference between consumer and provider is large then time adjust are made more quickly ~1min.

Slewing: When time difference is very less ~128ms the ntp will adjust time gradually around every 17 minutes

Insane Time: If time difference between consumer and provider is more than 17 min, then ntpd treats that time to be insane.

Drift: Your clock will drift due to fluctuations in the frequency oscillating the quartz crystal on your motherboard. A fluctuation of just 0.001% (0.00001, or 10 PPM) means losing or gaining about 1 second per day.

Latency: The time delay between when data is sent on a network to when it is received. Latency can make it difficult to synchronize processes over a network, especially when the latency is variable. The latency is added to the time it got from server to get the exact time.

Jitter: It is a measurement of the variance in latency on the network. If the latency on the network is constant, there is no jitter.

Configuring NTP

Here we will see how to configure a system to use NTP

#installing NTP on linux machine
yum install ntp
apt-get install ntp

Now we will edit the server for NTP. Open the file /etc/ntp.conf

And edit the server info as [server server_address]

you can get list of server from https://www.pool.ntp.org/en/. From the website choose the server closest to your geographical location.

Remembered, previously we talked about Insane Time (where system and server time difference is more than 17min), to prevent such situation we run below command to update the system time (close to actual time) to eliminate insane time issue

ntpdate server_address

#you can use google public ntp server 
#sometimes you need to run it more than once
ntpdate time.google.com

Note : Before running the above command make sure to turn of ntpd by [ntpd off] and start after executing above command [ntpd on].

Monitor time synchronization : ntpq -p , ntptrace
Log File of NTP :  /var/log/ntp.log

How is SNTP different from NTP ?

Simple Network Time Protocol (SNTP) is a simplified, client-only version of NTP. SNTP can receive only
the time from NTP servers; it cannot be used to provide time services to other systems.

SNTP typically provides time within 100 milliseconds of the accurate time, but it does not provide the complex
filtering and statistical mechanisms of NTP. In addition, SNTP does not authenticate traffic, although you
can configure extended access lists to provide some protection. An SNTP client is more vulnerable to servers
that have unexpected behavior than an NTP client, and should be used only in situations where strong
authentication is not required.

So that all to get the basics of NTP protocol if you are more interested to dig in, do visit Cisco NTP

Git – The Layman’s Guide : BASIC CONCEPTS and COMMANDS

GIT is basically a distributed repository (place to store code) where multiple contributors can work simultaneously and collaborate their work. It also serves as a Version Controls System (system that records changes to a file or set of files over time so that you can recall specific versions later).


GIT allows you to revert files back to a previous state, revert the entire project back to a previous state, review changes made over time, see who last modified something that might be causing a problem, who introduced an issue and when, and more. It can also help in the situations where someone screwed up the code and it’s not working anymore. You can use the Version Control System to revert back to a safe version where everything was working perfectly normal.


It is very important to understand GIT workflow. Let us learn a few key terms

Repository: This is your project (collection of source code). This is a GIT specific term and is a standalone unit for your project.

Working Directory: This is the working directory of your code. Here you edit your code and save changes.

Staging Area: When you are confident about your code and want to save it to the repository, You first bring it to the Staging area. You can bring your files in a sequential manner to the staging area.

Local Repository: When you have all the files you wanted to modify in the staging area and finally want to make changes to your repo, you save it to your local repo.

Remote Repository: Remote repo is a repository on a remote server which acts as a central repo for your project. Once you are 200% confident about your code. You move it to the remote repo.

Below diagram clearly explains how your code moves in the GIT environment.


Commands in Detail :

  • git add: add a file from working directory to staging area
  • git commit: add files from staging area to local repo
  • git push: add files from the local repo to the remote repo
  • git fetch: get files from the remote repo to the local repo (not working directory)
  • git merge: get files from the local repo to the working directory
  • git pull: get files from remote repo directly to the working directory (same as git fetch and git merge)
  • git status: gives info about all the files which are yet to be committed (to local repo)

These are the basic commands to use while working with GIT. How we will see how to use Git to work with our code.

STEP BY STEP guide to initializing and working with GIT

Check weather GIT is installed

$ git --verison


Tell GIT about your identity

$ git config --global user.name "YOUR_USERNAME" 
$ git config --global user.email "me@samteck.net"

$ git config --global --list # To check the info you just provided


Generate SSH and add to your GitHub account (more on ssh keys)

$ ssh-keygen -t rsa -b 4096 -C "me@samteck.net"

$ ssh -T git@github.com   # check your ssh connection

– Copy the public ssh key (id_rsa.pub) from /.ssh folder in your home directory to SSH settings in your GitHub account


Lets GITify our first directory
Navigate to your working directory (in terminal) and initialize the directory with

$ git init

this will create a hidden folder in the working directory where info about the repo will stored. Also, there is a file called – .gitignore (it stores the info about the files in the working directory which need to ignored in repo like OS related files)

Add files to the staging area (Index: view of your working directory that is ready for commit)

$ git add .   # add all the files in that folder

$ git add *file name*   # add specific files to staging area

Before committing the changes we can check the status of the working directory (staged and unstaged changes)

$ git status

When all the changes are staged we can commit our code which will be then stored in the local repo. It is a good practice to add a message with every commit so that other users can see what modification has been made. Also, it’s better to sync your workspace with remote repo before committing to check that no other commits were made on remote repo by any other user.

$ git commit -m "First commit"

NOTE: every commit can be identified with a commit hash (SHA-1). On Github, you can view that commit from below URL


Also, you can uncommit a change by

$ git reset HEAD~1

Add Remote Origin

Now we have created a local repo, but to add it to a remote repo we need to provide the address of remote repo

$ git remote add origin remote_repository_URL   # sets the new remote

$ git remote -v   # List the remote connections you have to other repositories.

$ git push -u origin master   # pushes changes to origin

Now you have successfully created a local repo and pushed it to the remote repo. If you open your GitHub account, you can see that your repo is available remotely on GitHub.

Useful GIT Commands

$ git diff   # To show the files changes not yet staged

$ git log    # view commit history

$ git clone remote_repository_URL   #download remote repo to working directory

$ git pull origin master         # update your local repo with changes on remote repo

$ git checkout <branch/commit>   # check out desired status of repo

When you git fetch, Git gathers any commits from the target branch that do not exist in your current branch and stores them in your local repository. However, it does not merge them with your current branch. This is particularly useful if you need to keep your repository up to date, but are working on something that might break if you update your files. To integrate the commits into your master branch, you use git merge.

Basically, this will be your control flow which you will be using most of the times.

$ git add .

$ git status # Lists all new or modified files to be committed

$ git commit -m "Second commit"

$ git push -u origin master

That’s all for the basic understanding of GIT. Thanks for reading.

What are SSH Keys and How to use them


Most of you guys must have logged onto servers using SSH protocol and verified yourself with a Password. Everything seems good, but don’t you sometimes feel a bit frustrated when every-time you have to enter the password, also entering the password is not the best way in terms of security (storing a password in scripts which auto logins to a server is not a good idea). That’s where the concept of SSH Keys comes into the picture.


‘SSH keys’ is one of the many ways of authenticating, while logging to a remote server over the internet. SSH keys work on the principle of Asymmetric cryptography where client and server have different keys and authentication is successful as long as these 2 keys fit the formula (as both of these keys are derived from a mathematical formula). Now we will see how to use SSH keys as a method of authentication.

STEP 1: Generate an SSH key pair

ssh-keygen -t rsa

This command will generate 2 keys under a hidden folder named ‘.ssh/‘ in your home directory. Before generating new keys its best to check if any previous keys are present (cd ./ssh)

The 2 generated keys are as follows :

PUBLIC KEY (id_rsa.pub): This key is given to the system (server) to which we are trying to connect.

PRIVATE KEY (id_rsa): This key is stored on the system from which we are trying to connect.

STEP 2: Upload the Public key on Server

Now you need to upload the Public Key to the server to which your client will connect. eg: while configuring ssh keys on Github we paste the public key in Github’s ssh keys settings.

ssh-copy-id root@

ssh-copy-id uses the SSH protocol to connect to the target host and upload the SSH user key. This command edits the authorized_keys file on the server. It creates the .ssh directory if it doesn’t exist. It creates the authorized keys file if it doesn’t exist. Effectively, copying the public key to the server.

STEP 3: Connecting to the Server

When the client tries to connect to the server, below sequence of operations take place


This creates an authentication mechanism based on “something you have” (the private key file) as opposes to “something you know” (a password or phrase). The best authentication mechanisms contain a component of both – this is why ssh-keygen prompts you for a passphrase to encrypt the private key.


NOTE: After the client is authenticated by the server an SSH tunnel is established. The data send over SSH is encrypted with a session key(which is shared between client and server after establishing the connection). Also, the session key uses a symmetrical cryptography technique.

How to Install NOOBS on Raspberry Pi

raspberry pi usb ports image

To start with Raspberry Pi you need an OS (operating system) to run on it like all personal computers. On this OS you will run all you programs and applications.

Like on your laptop you can install various OS – like Windows, Ubuntu etc. Similarly on your Raspberry Pi you can install various operating system.

raspberry pi logo

Check the list of Operating System Available for Raspberry PI

NOOBS stands for New Out Of the Box Operating system. NOOBS is an easy operating system installer which contains Raspbian. It also provides a selection of alternative operating systems which are then downloaded from the internet and installed.

Steps to Install NOOBS on SD Card

Buy an SD card 

Card capacity should be 8GB or more, preferably class-10 or more

Download Noobs

Click HERE and download the version of noobs (if you are unsure choose the option with Offline and Network install and Download Zip)

Prepare The Sd Card

Format your sd card with the tool given HERE (choose either for windows or Mac)

Insert your SD card into the computer or laptop’s SD card reader and make a note of the drive letter allocated to it, e.g. G:/

You will need to set “FORMAT SIZE ADJUSTMENT” option to “ON” in the “Options” menu to ensure that the entire SD card volume is formatted, and not just a single partition. After that click Format


Once your SD card has been formatted, drag all the files in the extracted NOOBS folder and drop them onto the SD card drive.
The necessary files will then be transferred to your SD card.
When this process has finished, safely remove the SD card and insert it into your Raspberry Pi.


Plug in your keyboard, mouse, and monitor cables.
Now plug the USB power cable into your Pi.
Your Raspberry Pi will boot, and a window will appear with a list of different operating systems(you will only get raspbian based on your download) that you can install. We recommend that you use Raspbian – tick the box next to Raspbian and click on Install.
Raspbian will then run through its installation process. Note that this can take a while.

Congratulations, Now you have successfully installed. After this the Rasoberry Pi will restart and load into its graphical interface.