Category Archives: CDI

1. AWS:How to create and activate a new account in AWS ?

AWS Account-creation scrn

How to create and activate a new account in AWS ?:

In this blog, you will see the required steps for creating and activating your new AWS account. Once have the activated account, you can start your other lab practices as I discuss in the class timely.

The following are the main 4 steps process we need to follow:

STEP1: Creating your account. It consists of 2 steps: a) Providing a valid e-mail address and choosing a password. b) Providing your contact information and setting your preferences.

STEP2: Add a payment method Please note; you need to have a valid CC to give its details. Amazon verifies its transaction also with a tiny charge and with a credit back. If by mistaken given wrong data please note; your account registration process will not be activated. You will be intimated by mail. This way Amazon is authenticating/authorizing us for AWS usage.

STEP3: Verify your phone number. You need to Provide a phone number where you can be reached in next few minutes, while creating your account.

STEP4: Choose the AWS Support plans. Time to time the AWS plans will be published. You need to choose the plan from the currently available plans for your needs. The relevant URL is given in the detailed steps section in this blog.

As a consolidated process, we can understand from the below flow chart. Which is from the collection of AWS process charts.

AWS Account-creation flowchart

Note:

I am not copying the screens due to privacy.

Detailed steps

STEP1: Detailed steps for Creating your account.

a). You need to go to Amazon Web Services home page URL: https://aws.amazon.com/

b). Now, Choose Sign Up. Click on Create an AWS account. You can see new page with Create an AWS account. You need to enter the required details. E-mail id, Pwd, AWS Account name [you can give any name for this]. And choose continue to go to next page. Please note; The above steps are valid for the new users of AWS. If you enter your email address entered incorrectly, you might not be able to access your account or change your password in the future. So you need to be careful on your data entry part. Let us assume; if you’ve signed in to AWS recently, it might say Sign In to the Console. So you need to login into your existing Account.

c). Now in the current page, choose Professional or personal. These two areas will give equal services. Depends on your need You can choose one of the options.

d). From the above options choosed, type the requested company or personal information entries. Note; At this point, You need to go through the AWS Customer Agreement to know their policies and procedures to follow while operating.

e). Finally, you choose Create Account and Continue options in the bottom.

f). Please note; at this point you will receive an e-mail to confirm that your account is created. Now, you can sign in to your new account using the valid email address and valid password you have supplied earlier.

Please note; we have done the Step1 only, the activation process is not yet completed to use the AWS services. Still we need to follow 3 more steps.

STEP2: Add a payment method- Detailed steps:

At this point; On the Payment Information page,

a) Choose the payment method as per the payment gateway standards which is displayed.

b) Type the requested information associated with your payment method. Please make sure the address for your payment method is the same as the address you provided for your account. Note; If your billing address is different; then choose Use a new address, type the billing address for your payment method.

c) Now, choose Secure Submit.

STEP3: Verify your phone number.

Please keep a valid and handy phone number at this point.

a) On this Phone Verification page, type a phone number where can use to accept incoming phone calls.

b) Enter the code displayed in the captcha. When you’re ready to receive a call, choose Call me now option.

c) In a few moments, an automated system will call you to your given phone number. Even it might have SMS feature also, if you are outside North America region.

d) Type the provided PIN on your phone’s keypad of the AWS screen. e) After the process is complete, choose Continue.

STEP4: Choose the AWS Support plans.

a) At this point please visit the below URL: https://aws.amazon.com/premiumsupport/features/

You can select the AWS support plans from the given list.

b) After your selection of a Support plan, a confirmation page denotes that your account is being activated.

c) Please note; Accounts are usually activated within a few minutes, but the process might take up to 24 hours. This process includes the validation of Bank/CC account given there.

d) Hence keep looking for a mail on this subject from Amazon to start your AWS services usage.

Assuming everything went well, and your AWS account is activated now.  Congratulations!

We can look into next lab with reference to the class session.

2. AWS: WordPress[WP] infrastructure creation using a free tier account

https://wordpress.com/post/vskumar.blog/2884

 

If you are interested to learn Virtualization with Vagrant visit:

1. Vagrant/Virtual Box:How to create Virtual Machine[VM] on Windows 10?:

 

Note:

If you are not a student of my class, and looking for it please contact me by mail with your LinkedIn identity. And send a connection request with a message on your need. You can use the below contacts. Please note; I teach globally.

 

Vcard-Shanthi Kumar V-v3

27.DevOps:Working with SSH for Ansible usage

ssh

Working with SSH for Ansible usage:
With reference to my blog on Ansible installation on Ubuntu VM,  https://vskumar.blog/2018/05/08/23-devops-how-to-install-ansible-on-ubuntu-linux-vm/

in this blog, I have demonstrated on playing around with ssh among three
ubuntu Vmware Virtual machines.

To use Ansible exercises we need to follow the below pre-requisites with ssh operations.

Pre-requisites for Ansible usage:
https://help.ubuntu.com/community/SSH/OpenSSH/Keys

SSH Keys for Ansible VMs usage:
Before using Ansible we need to make sure the SSH is installed in the
VMs.
I would like to give the steps for this setup as below:

Pre-requisite Step1:
Install OpenSSH on Ubuntu.
Update the package index using the following command:
sudo apt-get update

To install the OpenSSH server application as well as the other related
packages use the command below:
sudo apt-get install openssh-server

Further, you can install the OpenSSH client application using
the following command:
sudo apt-get install openssh-client

Pre-requisite Step2:
Configure OpenSSH on Ubuntu
Before making any changes in OpenSSH configuration,
we need to know how to manage the OpenSSH service on Ubuntu VMs.

How to check ssh version?:
use the command; ssh -V

i) To start the service we can use the following command:
sudo systemctl start sshd.service

ii) To stop the service we can use:
sudo systemctl stop sshd.service

iii) To restart the service we can use:
sudo systemctl restart sshd.service

iv) To check the status of the service we can use:
sudo systemctl status sshd.service

v) If we want to enable the service on system boot we can use:
sudo systemctl enable sshd.service

vi) If we want to disable the service on system boot we can use:
sudo systemctl disable sshd.service

vii) The configuration file for the OpenSSH server application
is in the folder:/etc/ssh/sshd_config
We need to update the default port in this file.
We need to make sure to create a backup of the original configuration before
making any changes:
sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.orig

We can edit the file by using a text editor of our choice either vi or vim, etc..
The first thing we must do is to change the default SSH listening port.
Open the file and locate the line that specifies the listening port:
Port 22
Change it to your desired port number. Ex: Port 1990

Save the file and close it.
Then restart the service for the changes to take effect.

Note:
After making any changes in the OpenSSH configuration you need to restart the service
for the changes to take effect.

Pre-requisite Step3: Create an SSH key pair
Please note, during Ansible exercise or other DevOps tools, we need to connect to other VMs using SSH keys.

Let us note; the Key-based authentication uses two keys, one “public” key that anyone is allowed
to see.
And another “private” key that only the owner is allowed to see.
To securely communicate using key-based authentication, one needs to create a key pair,
securely store the private key on the computer which we want to log in from [Source machine],
and store the public key on the other Virtual Machine[Target machine] one wants to log in to.
Using key based logins with ssh is generally considered more secure than using plain password logins.

Now, let us see these steps:
1. Generating RSA Keys:
Our first step involves creating a set of RSA keys for use in authentication.
This should be done on the client.
To create our public and private SSH keys we need to use the below commands:
mkdir ~/.ssh
chmod 700 ~/.ssh
ssh-keygen -t rsa

We will be prompted for a location to save the keys, and a passphrase for the keys.
This passphrase will protect our private key while it’s stored on the hard drive:

=== Sample Output ====>
Generating public/private rsa key pair.
Enter file in which to save the key (/home/b/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/b/.ssh/id_rsa.
Your public key has been saved in /home/b/.ssh/id_rsa.pub.
======================>
Note; An SSH key passphrase is a secondary form of security.
You need to remember it while logging the remote machine.
Now, our public key is now available as .ssh/id_rsa.pub in the home directory.

The file name and pwd can be given when you follow rigid security procedures as per your project setup. Here if you avoid in giving name/pwd, it makes us easy to copy the key file to target machine.

2. Transfer Client Key to Host:
The key we need to transfer to the host is the public one.
If we can log in to a computer over SSH using a password,
we can transfer our RSA key by doing the following from our own computer:
Command format:
====>
ssh-copy-id <username>@<host>
====>
Note: The <username> and <host> should be replaced by our username
and the name of the computer we’re transferring our key to.

TIP on Port# usage:
We cannot specify a port other than the standard port 22 [unless we changed it to
another port# in the target VM]. we can work around this by issuing the
command like this: ssh-copy-id “<username>@<host> -p <port_nr>”.
If we are using the standard port 22, we can ignore this tip.

We can make sure this worked by doing the below command test:
ssh <username>@<host>

We should be prompted for the passphrase for our key:
Enter passphrase for key ‘/home/<user>/.ssh/id_rsa’:
Enter your passphrase, and provided host is configured to allow key-based logins,
we should then be logged in as usual.

 

How to remove the existing SSH from Ubuntu ?
If we have already ssh we can use the below steps to remove and
get the latest setup.

Step1: Stop SSH service before uninstalling it.
service ssh stop

Step2: Now, we need to Uninstall and remove the ssh package from the machine by using the below
apt-get command.

apt-get purge openssh-server

Now you can check its status using ssh -VM
If it is not there you should not get the version.

Please note my VMs Ips,where i will apply some exercises timely:

IP of Ans-ControlMachine:
192.168.116.132

IP of VM1:
192.168.116.134

IP of VM2:
192.168.116.135

IP of VM3:
192.168.116.133

The machine names are prompted in CLI.
I am using these four Virtual machines on Vmware environment with player as well as Workstation.

I have played around with SSH among these machines.
I have copied most of the screen outputs in this content.

Removing SSH from one Virtual machine for installating procedure testing:
I have preloaded SSH earlier.
I am purging SSH in one Virtual machine to demonstrate the exercise.
And below I have copied the screen outputs also.

==== Screen outputs for Ans-ControlMachine =====>
=== Removing SSH from Ans-ControlMachine=========>
vskumar@ubuntu:~$ ssh -V
OpenSSH_7.2p2 Ubuntu-4ubuntu2.2, OpenSSL 1.0.2g 1 Mar 2016
vskumar@ubuntu:~$ cat /etc/hostname
Ans-ControlMachine
vskumar@ubuntu:~$ service ssh stop
Failed to stop ssh.service: Unit ssh.service not loaded.
vskumar@ubuntu:~$ service ssh status
● ssh.service
Loaded: not-found (Reason: No such file or directory)
Active: inactive (dead)
vskumar@ubuntu:~$
vskumar@ubuntu:~$ apt-get -purge openssh-server
E: Command line option ‘p’ [from -purge] is not understood in combination with the other options.
vskumar@ubuntu:~$ apt-get purge remove openssh-server
E: Could not open lock file /var/lib/dpkg/lock – open (13: Permission denied)
E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?
vskumar@ubuntu:~$ sudo apt-get purge remove openssh-server
Reading package lists… Done
Building dependency tree
Reading state information… Done
E: Unable to locate package remove
vskumar@ubuntu:~$ sudo apt-get purge openssh-server
Reading package lists… Done
Building dependency tree
Reading state information… Done
Package ‘openssh-server’ is not installed, so not removed
0 upgraded, 0 newly installed, 0 to remove and 432 not upgraded.

vskumar@ubuntu:~$ sudo apt-get purge openssh-client
Reading package lists… Done
Building dependency tree
Reading state information… Done
The following packages will be REMOVED:
openssh-client* snapd* ubuntu-core-launcher*
0 upgraded, 0 newly installed, 3 to remove and 429 not upgraded.
After this operation, 61.7 MB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database … 176110 files and directories currently installed.)
Removing ubuntu-core-launcher (2.25) …
Removing snapd (2.25) …
Warning: Stopping snapd.service, but it can still be activated by:
snapd.socket
Purging configuration files for snapd (2.25) …
Final directory cleanup
Discarding preserved snap namespaces
umount: /run/snapd/ns/*.mnt: mountpoint not found
umount: /run/snapd/ns/: mountpoint not found
Removing extra snap-confine apparmor rules
Removing snapd state
Removing openssh-client (1:7.2p2-4ubuntu2.2) …
Purging configuration files for openssh-client (1:7.2p2-4ubuntu2.2) …
Processing triggers for man-db (2.7.5-1) …

vskumar@ubuntu:~$
s for man-db (2.7.5-1) …
vskumar@ubuntu:~$
vskumar@ubuntu:~$ ssh -V
bash: /usr/bin/ssh: No such file or directory
vskumar@ubuntu:~$
== So we have completely removed the SSH ====>
=== from Ans-ControlMachine=========>

Installing SSH into Ans-ControlMachine:

Now, let me install the SSH server and client also.
Step1:
Let update the packages.
sudo apt-get update

== Output =======>
vskumar@ubuntu:~$ sudo apt-get update

Get:1 http://security.ubuntu.com/ubuntu xenial-security InRelease [107 kB]
Hit:2 http://us.archive.ubuntu.com/ubuntu xenial InRelease
Get:3 http://us.archive.ubuntu.com/ubuntu xenial-updates InRelease [109 kB]
Get:4 http://us.archive.ubuntu.com/ubuntu xenial-backports InRelease [107 kB]
Get:5 http://security.ubuntu.com/ubuntu xenial-security/main amd64 DEP-11 Metadata [67.7 kB]
Get:6 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 DEP-11 Metadata [319 kB]
Get:7 http://security.ubuntu.com/ubuntu xenial-security/main DEP-11 64×64 Icons [72.6 kB]
Get:8 http://security.ubuntu.com/ubuntu xenial-security/universe amd64 DEP-11 Metadata [107 kB]
Get:9 http://security.ubuntu.com/ubuntu xenial-security/universe DEP-11 64×64 Icons [147 kB]
Get:10 http://us.archive.ubuntu.com/ubuntu xenial-updates/main DEP-11 64×64 Icons [226 kB]
Get:11 http://us.archive.ubuntu.com/ubuntu xenial-updates/universe amd64 DEP-11 Metadata [246 kB]
Get:12 http://us.archive.ubuntu.com/ubuntu xenial-updates/universe DEP-11 64×64 Icons [331 kB]
Get:13 http://us.archive.ubuntu.com/ubuntu xenial-updates/multiverse amd64 DEP-11 Metadata [5,964 B]
Get:14 http://us.archive.ubuntu.com/ubuntu xenial-backports/main amd64 DEP-11 Metadata [3,324 B]
Get:15 http://us.archive.ubuntu.com/ubuntu xenial-backports/universe amd64 DEP-11 Metadata [5,088 B]
Fetched 1,853 kB in 11s (168 kB/s)
Reading package lists… Done
vskumar@ubuntu:~$
============>

Step2: Installing server
Now, we will use the below command to install ssh srver:
sudo apt-get install openssh-server

==== Screen output ======>
vskumar@ubuntu:~$ sudo apt-get install openssh-server
Reading package lists… Done
Building dependency tree
Reading state information… Done
The following additional packages will be installed:
ncurses-term openssh-client openssh-sftp-server ssh-import-id
Suggested packages:
ssh-askpass libpam-ssh keychain monkeysphere rssh molly-guard
The following NEW packages will be installed:
ncurses-term openssh-client openssh-server openssh-sftp-server ssh-import-id
0 upgraded, 5 newly installed, 0 to remove and 429 not upgraded.
Need to get 1,222 kB of archives.
After this operation, 8,917 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 openssh-client amd64 1:7.2p2-4ubuntu2.4 [589 kB]
Get:2 http://us.archive.ubuntu.com/ubuntu xenial/main amd64 ncurses-term all 6.0+20160213-1ubuntu1 [249 kB]
Get:3 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 openssh-sftp-server amd64 1:7.2p2-4ubuntu2.4 [38.7 kB]
Get:4 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 openssh-server amd64 1:7.2p2-4ubuntu2.4 [335 kB]
Get:5 http://us.archive.ubuntu.com/ubuntu xenial/main amd64 ssh-import-id all 5.5-0ubuntu1 [10.2 kB]
Fetched 1,222 kB in 7s (162 kB/s)
Preconfiguring packages …
Selecting previously unselected package openssh-client.
(Reading database … 176023 files and directories currently installed.)
Preparing to unpack …/openssh-client_1%3a7.2p2-4ubuntu2.4_amd64.deb …
Unpacking openssh-client (1:7.2p2-4ubuntu2.4) …
Selecting previously unselected package ncurses-term.
Preparing to unpack …/ncurses-term_6.0+20160213-1ubuntu1_all.deb …
Unpacking ncurses-term (6.0+20160213-1ubuntu1) …
Selecting previously unselected package openssh-sftp-server.
Preparing to unpack …/openssh-sftp-server_1%3a7.2p2-4ubuntu2.4_amd64.deb …
Unpacking openssh-sftp-server (1:7.2p2-4ubuntu2.4) …
Selecting previously unselected package openssh-server.
Preparing to unpack …/openssh-server_1%3a7.2p2-4ubuntu2.4_amd64.deb …
Unpacking openssh-server (1:7.2p2-4ubuntu2.4) …
Selecting previously unselected package ssh-import-id.
Preparing to unpack …/ssh-import-id_5.5-0ubuntu1_all.deb …
Unpacking ssh-import-id (5.5-0ubuntu1) …
Processing triggers for man-db (2.7.5-1) …
Processing triggers for ufw (0.35-0ubuntu2) …
Processing triggers for systemd (229-4ubuntu19) …
Processing triggers for ureadahead (0.100.0-19) …
Setting up openssh-client (1:7.2p2-4ubuntu2.4) …
Setting up ncurses-term (6.0+20160213-1ubuntu1) …
Setting up openssh-sftp-server (1:7.2p2-4ubuntu2.4) …
Setting up openssh-server (1:7.2p2-4ubuntu2.4) …
Creating SSH2 RSA key; this may take some time …
2048 SHA256:3yMAIuH8WhE4tf0kwEqrBHo7gxj3nYq/RTXhYMrpz/s root@ubuntu (RSA)
Creating SSH2 DSA key; this may take some time …
1024 SHA256:HoY3UATMD48l8tOWSWQcJWtwK+s98j7WpD7WGEPsbVo root@ubuntu (DSA)
Creating SSH2 ECDSA key; this may take some time …
256 SHA256:sIDDAzkiGiTCzpGHOTEU3QbG/oNn4DNvXxHtm7kzAZ4 root@ubuntu (ECDSA)
Creating SSH2 ED25519 key; this may take some time …
256 SHA256:hGlI7mLNIGbU2bs/igS1YZrNwxxCvFpszZxOCAOozGk root@ubuntu (ED25519)
Setting up ssh-import-id (5.5-0ubuntu1) …
Processing triggers for systemd (229-4ubuntu19) …
Processing triggers for ureadahead (0.100.0-19) …
Processing triggers for ufw (0.35-0ubuntu2) …
vskumar@ubuntu:~$ ssh -V
OpenSSH_7.2p2 Ubuntu-4ubuntu2.4, OpenSSL 1.0.2g 1 Mar 2016
vskumar@ubuntu:~$
=======================>

Step3: install client
We can try to install the OpenSSH client application using
the following command:
sudo apt-get install openssh-client

==== Screen output =====================>
vskumar@ubuntu:~$
vskumar@ubuntu:~$ sudo apt-get install openssh-client
Reading package lists… Done
Building dependency tree
Reading state information… Done
openssh-client is already the newest version (1:7.2p2-4ubuntu2.4).
openssh-client set to manually installed.
0 upgraded, 0 newly installed, 0 to remove and 429 not upgraded.
vskumar@ubuntu:~$
=== It is installed along with server ====>

Step4:
Now, let us check the status:

=== Status of SSH server ===>
vskumar@ubuntu:~$ sudo systemctl status sshd.service
● ssh.service – OpenBSD Secure Shell server
Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enab
Active: active (running) since Sat 2018-05-26 05:21:18 PDT; 6min ago
Main PID: 4645 (sshd)
CGroup: /system.slice/ssh.service
└─4645 /usr/sbin/sshd -D

May 26 05:21:17 ubuntu systemd[1]: Starting OpenBSD Secure Shell server…
May 26 05:21:17 ubuntu sshd[4645]: Server listening on 0.0.0.0 port 22.
May 26 05:21:17 ubuntu sshd[4645]: Server listening on :: port 22.
May 26 05:21:18 ubuntu systemd[1]: Started OpenBSD Secure Shell server.
lines 1-11/11 (END)
vskumar@ubuntu:~$
============================>

Generating RSA Keys:
Step1:
To create our public and private SSH keys we need to use the below commands:
mkdir ~/.ssh
chmod 700 ~/.ssh
ssh-keygen -t rsa

=== Screen output ===>
vskumar@ubuntu:~$ ls
Desktop Downloads Music Public Videos
Documents examples.desktop Pictures Templates
vskumar@ubuntu:~$ ls -la
total 116
drwxr-xr-x 17 vskumar vskumar 4096 May 26 05:30 .
drwxr-xr-x 3 root root 4096 Nov 22 2017 ..
-rw——- 1 vskumar vskumar 524 Mar 6 18:06 .bash_history
-rw-r–r– 1 vskumar vskumar 220 Nov 22 2017 .bash_logout
-rw-r–r– 1 vskumar vskumar 3771 Nov 22 2017 .bashrc
drwx—— 13 vskumar vskumar 4096 May 26 04:45 .cache
drwx—— 14 vskumar vskumar 4096 Nov 22 2017 .config
drwxr-xr-x 2 vskumar vskumar 4096 Nov 22 2017 Desktop
-rw-r–r– 1 vskumar vskumar 25 Nov 22 2017 .dmrc
drwxr-xr-x 2 vskumar vskumar 4096 Nov 22 2017 Documents
drwxr-xr-x 2 vskumar vskumar 4096 Nov 22 2017 Downloads
-rw-r–r– 1 vskumar vskumar 8980 Nov 22 2017 examples.desktop
drwx—— 2 vskumar vskumar 4096 Dec 22 21:36 .gconf
drwx—— 3 vskumar vskumar 4096 May 26 04:42 .gnupg
-rw——- 1 vskumar vskumar 3498 May 26 04:42 .ICEauthority
drwx—— 3 vskumar vskumar 4096 Nov 22 2017 .local
drwx—— 4 vskumar vskumar 4096 Nov 22 2017 .mozilla
drwxr-xr-x 2 vskumar vskumar 4096 Nov 22 2017 Music
drwxr-xr-x 2 vskumar vskumar 4096 Nov 22 2017 Pictures
-rw-r–r– 1 vskumar vskumar 655 Nov 22 2017 .profile
drwxr-xr-x 2 vskumar vskumar 4096 Nov 22 2017 Public
drwxrwxr-x 2 vskumar vskumar 4096 May 26 05:30 .ssh
-rw-r–r– 1 vskumar vskumar 0 Nov 22 2017 .sudo_as_admin_successful
drwxr-xr-x 2 vskumar vskumar 4096 Nov 22 2017 Templates
drwxr-xr-x 2 vskumar vskumar 4096 Nov 22 2017 Videos
-rw——- 1 vskumar vskumar 51 May 26 04:42 .Xauthority
-rw——- 1 vskumar vskumar 82 May 26 04:42 .xsession-errors
-rw——- 1 vskumar vskumar 82 May 26 03:11 .xsession-errors.old
vskumar@ubuntu:~$
vskumar@ubuntu:~$ chmod 700 ~/.ssh
I copied on the below line:
drwx—— 2 vskumar vskumar 4096 May 26 05:30 .ssh
The rights are changed.
======================>

=========================>
vskumar@ubuntu:~$
vskumar@ubuntu:~$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/vskumar/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/vskumar/.ssh/id_rsa.
Your public key has been saved in /home/vskumar/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:jLVDx+RqfC+3lo3qcajm+gcHO+44+h/cfTDDLHtsEAg vskumar@ubuntu
The key’s randomart image is:
+—[RSA 2048]—-+
| E . |
| . = |
| + = |
| *.+ + |
| . So+ * |
| o++.O + |
| .o+* O+. |
| ..oo.B+o. |
| .o+O*ooo. |
+—-[SHA256]—–+
vskumar@ubuntu:~$
=== I have given the pwd for passphrase ====>

Step2: Transfer Client Key to Host
ssh-copy-id <username>@<host>
I will try with VM1.
==== Copting ssh id to VM1 ====>
== From Ans-ControlMachine ====>
vskumar@ubuntu:~/.ssh$ cat /etc/hostname
Ans-ControlMachine
vskumar@ubuntu:~/.ssh$ ls
id_rsa id_rsa.pub known_hosts
vskumar@ubuntu:~/.ssh$ ssh ssh-copy-id vskumar@192.168.116.134
ssh: Could not resolve hostname ssh-copy-id: Name or service not known
vskumar@ubuntu:~/.ssh$ sudo ssh-copy-id vskumar@192.168.116.134
[sudo] password for vskumar:
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: “/home/vskumar/.ssh/id_rsa.pub”
The authenticity of host ‘192.168.116.134 (192.168.116.134)’ can’t be established.
ECDSA key fingerprint is SHA256:ZPPT6yQv8nAC1A6cDkeIssDYiim81f4/88I+NNVm1Iw.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed — if you are prompted now it is to install the new keys
vskumar@192.168.116.134’s password:

Number of key(s) added: 1

Now try logging into the machine, with: “ssh ‘vskumar@192.168.116.134′”
and check to make sure that only the key(s) you wanted were added.

vskumar@ubuntu:~/.ssh$

==== Copied ssh key to VM1 ===>

======From VM1 =====>
vskumar@VM1:~$
vskumar@VM1:~$ ssh -V
OpenSSH_7.2p2 Ubuntu-4ubuntu2.2, OpenSSL 1.0.2g 1 Mar 2016
vskumar@VM1:~$ service ssh stop
Failed to stop ssh.service: Unit ssh.service not loaded.
vskumar@VM1:~$ apt-get -purge openssh-server
E: Command line option ‘p’ [from -purge] is not understood in combination with the other options.
vskumar@VM1:~$ sudo apt-get -purge openssh-server
[sudo] password for vskumar:
E: Command line option ‘p’ [from -purge] is not understood in combination with the other options.
vskumar@VM1:~$ sudo apt-get purge openssh-server
Reading package lists… Done
Building dependency tree
Reading state information… Done
Package ‘openssh-server’ is not installed, so not removed
0 upgraded, 0 newly installed, 0 to remove and 432 not upgraded.
vskumar@VM1:~$ ssh -V
OpenSSH_7.2p2 Ubuntu-4ubuntu2.2, OpenSSL 1.0.2g 1 Mar 2016
vskumar@VM1:~$ sudo apt-get purge openssh-client
Reading package lists… Done
Building dependency tree
Reading state information… Done
The following packages will be REMOVED:
openssh-client* snapd* ubuntu-core-launcher*
0 upgraded, 0 newly installed, 3 to remove and 429 not upgraded.
After this operation, 61.7 MB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database … 176110 files and directories currently installed.)
Removing ubuntu-core-launcher (2.25) …
Removing snapd (2.25) …
Warning: Stopping snapd.service, but it can still be activated by:
snapd.socket
Purging configuration files for snapd (2.25) …
Final directory cleanup
Discarding preserved snap namespaces
umount: /run/snapd/ns/*.mnt: mountpoint not found
umount: /run/snapd/ns/: mountpoint not found
Removing extra snap-confine apparmor rules
Removing snapd state
Removing openssh-client (1:7.2p2-4ubuntu2.2) …
Purging configuration files for openssh-client (1:7.2p2-4ubuntu2.2) …
Processing triggers for man-db (2.7.5-1) …
vskumar@VM1:~$
vskumar@VM1:~$ ssh -V
bash: /usr/bin/ssh: No such file or directory
vskumar@VM1:~$

vskumar@VM1:~$ sudo apt-get update
0% [Working]
Get:1 http://security.ubuntu.com/ubuntu xenial-security InRelease [107 kB]
Hit:2 http://us.archive.ubuntu.com/ubuntu xenial InRelease
Get:3 http://us.archive.ubuntu.com/ubuntu xenial-updates InRelease [109 kB]
Get:4 http://us.archive.ubuntu.com/ubuntu xenial-backports InRelease [107 kB]
Get:5 http://security.ubuntu.com/ubuntu xenial-security/main amd64 DEP-11 Metadata [67.7 kB]
Get:6 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 Packages [783 kB]
Get:7 http://security.ubuntu.com/ubuntu xenial-security/main DEP-11 64×64 Icons [72.6 kB]
Get:8 http://security.ubuntu.com/ubuntu xenial-security/universe amd64 DEP-11 Metadata [107 kB]
Get:9 http://security.ubuntu.com/ubuntu xenial-security/universe DEP-11 64×64 Icons [147 kB]
Get:10 http://us.archive.ubuntu.com/ubuntu xenial-updates/main i386 Packages [718 kB]
Get:11 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 DEP-11 Metadata [319 kB]
Get:12 http://us.archive.ubuntu.com/ubuntu xenial-updates/main DEP-11 64×64 Icons [226 kB]
Get:13 http://us.archive.ubuntu.com/ubuntu xenial-updates/universe amd64 Packages [631 kB]
Get:14 http://us.archive.ubuntu.com/ubuntu xenial-updates/universe i386 Packages [577 kB]
Get:15 http://us.archive.ubuntu.com/ubuntu xenial-updates/universe amd64 DEP-11 Metadata [246 kB]
Get:16 http://us.archive.ubuntu.com/ubuntu xenial-updates/universe DEP-11 64×64 Icons [331 kB]
Get:17 http://us.archive.ubuntu.com/ubuntu xenial-updates/multiverse amd64 DEP-11 Metadata [5,964 B]
Get:18 http://us.archive.ubuntu.com/ubuntu xenial-backports/main amd64 DEP-11 Metadata [3,324 B]
Get:19 http://us.archive.ubuntu.com/ubuntu xenial-backports/universe amd64 DEP-11 Metadata [5,088 B]
Fetched 4,562 kB in 24s (187 kB/s)
Reading package lists… Done
vskumar@VM1:~$

vskumar@VM1:~$
vskumar@VM1:~$ sudo apt-get install openssh-server
Reading package lists… Done
Building dependency tree
Reading state information… Done
The following additional packages will be installed:
ncurses-term openssh-client openssh-sftp-server ssh-import-id
Suggested packages:
ssh-askpass libpam-ssh keychain monkeysphere rssh molly-guard
The following NEW packages will be installed:
ncurses-term openssh-client openssh-server openssh-sftp-server ssh-import-id
0 upgraded, 5 newly installed, 0 to remove and 429 not upgraded.
Need to get 1,222 kB of archives.
After this operation, 8,917 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 openssh-client amd64 1:7.2p2-4ubuntu2.4 [589 kB]
Get:2 http://us.archive.ubuntu.com/ubuntu xenial/main amd64 ncurses-term all 6.0+20160213-1ubuntu1 [249 kB]
Get:3 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 openssh-sftp-server amd64 1:7.2p2-4ubuntu2.4 [38.7 kB]
Get:4 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 openssh-server amd64 1:7.2p2-4ubuntu2.4 [335 kB]
Get:5 http://us.archive.ubuntu.com/ubuntu xenial/main amd64 ssh-import-id all 5.5-0ubuntu1 [10.2 kB]
Fetched 1,222 kB in 7s (160 kB/s)
Preconfiguring packages …
Selecting previously unselected package openssh-client.
(Reading database … 176023 files and directories currently installed.)
Preparing to unpack …/openssh-client_1%3a7.2p2-4ubuntu2.4_amd64.deb …
Unpacking openssh-client (1:7.2p2-4ubuntu2.4) …
Selecting previously unselected package ncurses-term.
Preparing to unpack …/ncurses-term_6.0+20160213-1ubuntu1_all.deb …
Unpacking ncurses-term (6.0+20160213-1ubuntu1) …
Selecting previously unselected package openssh-sftp-server.
Preparing to unpack …/openssh-sftp-server_1%3a7.2p2-4ubuntu2.4_amd64.deb …
Unpacking openssh-sftp-server (1:7.2p2-4ubuntu2.4) …
Selecting previously unselected package openssh-server.
Preparing to unpack …/openssh-server_1%3a7.2p2-4ubuntu2.4_amd64.deb …
Unpacking openssh-server (1:7.2p2-4ubuntu2.4) …
Selecting previously unselected package ssh-import-id.
Preparing to unpack …/ssh-import-id_5.5-0ubuntu1_all.deb …
Unpacking ssh-import-id (5.5-0ubuntu1) …
Processing triggers for man-db (2.7.5-1) …
Processing triggers for ufw (0.35-0ubuntu2) …
Processing triggers for systemd (229-4ubuntu19) …
Processing triggers for ureadahead (0.100.0-19) …
Setting up openssh-client (1:7.2p2-4ubuntu2.4) …
Setting up ncurses-term (6.0+20160213-1ubuntu1) …
Setting up openssh-sftp-server (1:7.2p2-4ubuntu2.4) …
Setting up openssh-server (1:7.2p2-4ubuntu2.4) …
Creating SSH2 RSA key; this may take some time …
2048 SHA256:4efQhtH82rrRfTvvYxt3Wu7lJg0HJcW66yEi6WaTN+c root@VM1 (RSA)
Creating SSH2 DSA key; this may take some time …
1024 SHA256:fGZ3vX279MRTXsRhzYyHSPIwVv7ge2/WRQmh+SHlIZo root@VM1 (DSA)
Creating SSH2 ECDSA key; this may take some time …
256 SHA256:ZPPT6yQv8nAC1A6cDkeIssDYiim81f4/88I+NNVm1Iw root@VM1 (ECDSA)
Creating SSH2 ED25519 key; this may take some time …
256 SHA256:5rZGM1Q0vbVD82kcvKS4NdtzCGgDIaiEjL+C01+iJgU root@VM1 (ED25519)
Setting up ssh-import-id (5.5-0ubuntu1) …
Processing triggers for systemd (229-4ubuntu19) …
Processing triggers for ureadahead (0.100.0-19) …
Processing triggers for ufw (0.35-0ubuntu2) …
vskumar@VM1:~$
vskumar@VM1:~$ ssh -V
OpenSSH_7.2p2 Ubuntu-4ubuntu2.4, OpenSSL 1.0.2g 1 Mar 2016
vskumar@VM1:~$

==========================>

 

===Connecting to >
vskumar@VM1:~$ ssh vskumar@Ans-ControlMachine
ssh: Could not resolve hostname ans-controlmachine: Name or service not known
vskumar@VM1:~$ ssh vskumar@192.168.116.132
The authenticity of host ‘192.168.116.132 (192.168.116.132)’ can’t be established.
ECDSA key fingerprint is SHA256:sIDDAzkiGiTCzpGHOTEU3QbG/oNn4DNvXxHtm7kzAZ4.
Are you sure you want to continue connecting (yes/no)? y
Please type ‘yes’ or ‘no’: yes
Warning: Permanently added ‘192.168.116.132’ (ECDSA) to the list of known hosts.
vskumar@192.168.116.132’s password:
Welcome to Ubuntu 16.04.3 LTS (GNU/Linux 4.10.0-28-generic x86_64)

* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage

437 packages can be updated.
251 updates are security updates.

 

The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.

vskumar@ubuntu:~$

vskumar@ubuntu:~$ pwd
/home/vskumar
vskumar@ubuntu:~$ cat /etc/hostname
Ans-ControlMachine
vskumar@ubuntu:~$ exit
logout
Connection to 192.168.116.132 closed.
vskumar@VM1:~$ cat /etc/hostname
VM1
vskumar@VM1:~$
==== Connected from VM1 to ======>
==== Ans-ControlMachine and exit ======>

I am connecting to VM1 from Ans-ControlMachine through ssh.

== Connecting to VM1 from ==>
====Ans-ControlMachine =====>
vskumar@ubuntu:~/.ssh$ ssh vskumar@192.168.116.134
The authenticity of host ‘192.168.116.134 (192.168.116.134)’ can’t be established.
ECDSA key fingerprint is SHA256:ZPPT6yQv8nAC1A6cDkeIssDYiim81f4/88I+NNVm1Iw.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added ‘192.168.116.134’ (ECDSA) to the list of known hosts.
vskumar@192.168.116.134’s password:
Welcome to Ubuntu 16.04.3 LTS (GNU/Linux 4.10.0-28-generic x86_64)

* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage

437 packages can be updated.
251 updates are security updates.

 

The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.

vskumar@VM1:~$ cat /etc/hostname
VM1
vskumar@VM1:~$
vskumar@VM1:~$
vskumar@VM1:~$ exit
logout
Connection to 192.168.116.134 closed.
vskumar@ubuntu:~/.ssh$
vskumar@ubuntu:~/.ssh$ cat /etc/hostname
Ans-ControlMachine
vskumar@ubuntu:~/.ssh$
======= Exit from VM1 And back ====>
==== to Ans-ControlMachine ====>

 

=== Connecting from VM1 to VM2 ===>
== Connecting in the same SSH ====>
== From VM1 to Ans-ControlMachine ====>
== You can play around with ssh ====>
== Across VMs by using IPs ========>
vskumar@VM2:~$ ssh -V
OpenSSH_7.2p2 Ubuntu-4ubuntu2.2, OpenSSL 1.0.2g 1 Mar 2016
vskumar@VM2:~$ sudo ssh vskumar@VM1
[sudo] password for vskumar:
ssh: Could not resolve hostname vm1: Name or service not known
vskumar@VM2:~$ sudo ssh vskumar@192.168.116.134
The authenticity of host ‘192.168.116.134 (192.168.116.134)’ can’t be established.
ECDSA key fingerprint is SHA256:ZPPT6yQv8nAC1A6cDkeIssDYiim81f4/88I+NNVm1Iw.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added ‘192.168.116.134’ (ECDSA) to the list of known hosts.
vskumar@192.168.116.134’s password:
Welcome to Ubuntu 16.04.3 LTS (GNU/Linux 4.10.0-28-generic x86_64)

* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage

437 packages can be updated.
251 updates are security updates.

Last login: Sat May 26 06:00:10 2018 from 192.168.116.132
vskumar@VM1:~$ cat /etc/hostname
VM1
vskumar@VM1:~$ ssh vskumar@192.168.116.132
vskumar@192.168.116.132’s password:
Welcome to Ubuntu 16.04.3 LTS (GNU/Linux 4.10.0-28-generic x86_64)

* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage

437 packages can be updated.
251 updates are security updates.

Last login: Sat May 26 05:55:36 2018 from 192.168.116.134
vskumar@ubuntu:~$ cat /etc/hostname
Ans-ControlMachine
vskumar@ubuntu:~$
vskumar@ubuntu:~$ exit
logout
Connection to 192.168.116.132 closed.
vskumar@VM1:~$

vskumar@VM1:~$ exit
logout
Connection to 192.168.116.134 closed.
vskumar@VM2:~$ cat /etc/hostname
VM2
vskumar@VM2:~$
== We have played around 3 VMs ===>
=== With SSH =====================>

 

=== Connecting from VM2 ===>
==== tO Ans-ControlMachine===>
vskumar@VM2:~$ ssh vskumar@192.168.116.132
The authenticity of host ‘192.168.116.132 (192.168.116.132)’ can’t be established.
ECDSA key fingerprint is SHA256:sIDDAzkiGiTCzpGHOTEU3QbG/oNn4DNvXxHtm7kzAZ4.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added ‘192.168.116.132’ (ECDSA) to the list of known hosts.
vskumar@192.168.116.132’s password:
Welcome to Ubuntu 16.04.3 LTS (GNU/Linux 4.10.0-28-generic x86_64)

* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage

437 packages can be updated.
251 updates are security updates.

Last login: Sat May 26 06:05:18 2018 from 192.168.116.134
vskumar@ubuntu:~$
vskumar@ubuntu:~$ cat /etc/hostname
Ans-ControlMachine
vskumar@ubuntu:~$
vskumar@ubuntu:~$ exit
logout
Connection to 192.168.116.132 closed.
vskumar@VM2:~$
==== Conneted from VM2 ==>

=== Removing ssh from VM2 ====>
== To have clean files ========>
vskumar@VM2:~$ sudo apt-get purge openssh-client
Reading package lists… Done
Building dependency tree
Reading state information… Done
The following packages will be REMOVED:
openssh-client* snapd* ubuntu-core-launcher*
0 upgraded, 0 newly installed, 3 to remove and 429 not upgraded.
After this operation, 61.7 MB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database … 176110 files and directories currently installed.)
Removing ubuntu-core-launcher (2.25) …
Removing snapd (2.25) …
Warning: Stopping snapd.service, but it can still be activated by:
snapd.socket
Purging configuration files for snapd (2.25) …
Final directory cleanup
Discarding preserved snap namespaces
umount: /run/snapd/ns/*.mnt: mountpoint not found
umount: /run/snapd/ns/: mountpoint not found
Removing extra snap-confine apparmor rules
Removing snapd state
Removing openssh-client (1:7.2p2-4ubuntu2.2) …
Purging configuration files for openssh-client (1:7.2p2-4ubuntu2.2) …
Processing triggers for man-db (2.7.5-1) …
vskumar@VM2:~$
vskumar@VM2:~$ ssh -V
bash: /usr/bin/ssh: No such file or directory
vskumar@VM2:~$
===== SSH is removed in VM2 ====>

=== Installing ssh in VM2 ====>
vskumar@VM2:~$ sudo apt-get install openssh-server
Reading package lists… Done
Building dependency tree
Reading state information… Done
The following additional packages will be installed:
ncurses-term openssh-client openssh-sftp-server ssh-import-id
Suggested packages:
ssh-askpass libpam-ssh keychain monkeysphere rssh molly-guard
The following NEW packages will be installed:
ncurses-term openssh-client openssh-server openssh-sftp-server ssh-import-id
0 upgraded, 5 newly installed, 0 to remove and 429 not upgraded.
Need to get 633 kB/1,222 kB of archives.
After this operation, 8,917 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://us.archive.ubuntu.com/ubuntu xenial/main amd64 ncurses-term all 6.0+20160213-1ubuntu1 [249 kB]
Get:2 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 openssh-sftp-server amd64 1:7.2p2-4ubuntu2.4 [38.7 kB]
Get:3 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 openssh-server amd64 1:7.2p2-4ubuntu2.4 [335 kB]
Get:4 http://us.archive.ubuntu.com/ubuntu xenial/main amd64 ssh-import-id all 5.5-0ubuntu1 [10.2 kB]
Fetched 633 kB in 34s (18.5 kB/s)
Preconfiguring packages …
Selecting previously unselected package openssh-client.
(Reading database … 176023 files and directories currently installed.)
Preparing to unpack …/openssh-client_1%3a7.2p2-4ubuntu2.4_amd64.deb …
Unpacking openssh-client (1:7.2p2-4ubuntu2.4) …
Selecting previously unselected package ncurses-term.
Preparing to unpack …/ncurses-term_6.0+20160213-1ubuntu1_all.deb …
Unpacking ncurses-term (6.0+20160213-1ubuntu1) …
Selecting previously unselected package openssh-sftp-server.
Preparing to unpack …/openssh-sftp-server_1%3a7.2p2-4ubuntu2.4_amd64.deb …
Unpacking openssh-sftp-server (1:7.2p2-4ubuntu2.4) …
Selecting previously unselected package openssh-server.
Preparing to unpack …/openssh-server_1%3a7.2p2-4ubuntu2.4_amd64.deb …
Unpacking openssh-server (1:7.2p2-4ubuntu2.4) …
Selecting previously unselected package ssh-import-id.
Preparing to unpack …/ssh-import-id_5.5-0ubuntu1_all.deb …
Unpacking ssh-import-id (5.5-0ubuntu1) …
Processing triggers for man-db (2.7.5-1) …
Processing triggers for ufw (0.35-0ubuntu2) …
Processing triggers for systemd (229-4ubuntu19) …
Processing triggers for ureadahead (0.100.0-19) …
Setting up openssh-client (1:7.2p2-4ubuntu2.4) …
Setting up ncurses-term (6.0+20160213-1ubuntu1) …
Setting up openssh-sftp-server (1:7.2p2-4ubuntu2.4) …
Setting up openssh-server (1:7.2p2-4ubuntu2.4) …
Creating SSH2 RSA key; this may take some time …
2048 SHA256:JzaY4P+pXshET4rzo/+nkNxGxWe9Hl2Vljd5OV9upko root@VM2 (RSA)
Creating SSH2 DSA key; this may take some time …
1024 SHA256:M49R3FKLVlxGFRw8Caf+s1ktna9h3Ak5Ls93+TyBrac root@VM2 (DSA)
Creating SSH2 ECDSA key; this may take some time …
256 SHA256:/HtM2RyrOSeFO01WW3d1S5fcB9mBM7MApniY54Nq4k4 root@VM2 (ECDSA)
Creating SSH2 ED25519 key; this may take some time …
256 SHA256:lbmYMsRLrCR23898dlX4TidNFYkasm3w/lpyl0oZXfg root@VM2 (ED25519)
Setting up ssh-import-id (5.5-0ubuntu1) …
Processing triggers for systemd (229-4ubuntu19) …
Processing triggers for ureadahead (0.100.0-19) …
Processing triggers for ufw (0.35-0ubuntu2) …
vskumar@VM2:~$ ssh -V
OpenSSH_7.2p2 Ubuntu-4ubuntu2.4, OpenSSL 1.0.2g 1 Mar 2016
vskumar@VM2:~$
== Now VM2 has the complete ssh =====>

=== Now let me connect to ===>
====Ans-ControlMachine ======>
== From VM2 =================>

vskumar@VM2:~$ sudo ssh vskumar@192.168.116.132
The authenticity of host ‘192.168.116.132 (192.168.116.132)’ can’t be established.
ECDSA key fingerprint is SHA256:sIDDAzkiGiTCzpGHOTEU3QbG/oNn4DNvXxHtm7kzAZ4.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added ‘192.168.116.132’ (ECDSA) to the list of known hosts.
vskumar@192.168.116.132’s password:
Welcome to Ubuntu 16.04.3 LTS (GNU/Linux 4.10.0-28-generic x86_64)

* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage

437 packages can be updated.
251 updates are security updates.

Last login: Sat May 26 06:58:14 2018 from 192.168.116.135
vskumar@ubuntu:~$ cat /etc/hostname
Ans-ControlMachine
vskumar@ubuntu:~$
vskumar@ubuntu:~$ exit
logout
Connection to 192.168.116.132 closed.
vskumar@VM2:~$
== Connected and exited ====>

=== Now let me connect to ===>
====From Ans-ControlMachine ======>
==== TO VM2 =================>
vskumar@ubuntu:~/.ssh$ ssh vskumar@192.168.116.135
The authenticity of host ‘192.168.116.135 (192.168.116.135)’ can’t be established.
ECDSA key fingerprint is SHA256:/HtM2RyrOSeFO01WW3d1S5fcB9mBM7MApniY54Nq4k4.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added ‘192.168.116.135’ (ECDSA) to the list of known hosts.
vskumar@192.168.116.135’s password:
Welcome to Ubuntu 16.04.3 LTS (GNU/Linux 4.10.0-28-generic x86_64)

* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage

437 packages can be updated.
251 updates are security updates.

The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.

vskumar@VM2:~$ cat /etc/hostname
VM2
vskumar@VM2:~$
vskumar@VM2:~$ exit
logout
Connection to 192.168.116.135 closed.
vskumar@ubuntu:~/.ssh$
===== Connected to VM2 and exited ===>

== SSh key added in VM2 ===>
====From Ans-ControlMachine ======>
vskumar@ubuntu:~/.ssh$
vskumar@ubuntu:~/.ssh$ ssh ssh-copy-id vskumar@192.168.116.135
ssh: Could not resolve hostname ssh-copy-id: Name or service not known
vskumar@ubuntu:~/.ssh$ sudo ssh-copy-id vskumar@192.168.116.135
[sudo] password for vskumar:
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: “/home/vskumar/.ssh/id_rsa.pub”
The authenticity of host ‘192.168.116.135 (192.168.116.135)’ can’t be established.
ECDSA key fingerprint is SHA256:/HtM2RyrOSeFO01WW3d1S5fcB9mBM7MApniY54Nq4k4.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed — if you are prompted now it is to install the new keys
vskumar@192.168.116.135’s password:

Number of key(s) added: 1

Now try logging into the machine, with: “ssh ‘vskumar@192.168.116.135′”
and check to make sure that only the key(s) you wanted were added.

vskumar@ubuntu:~/.ssh$
===== So now, we have made correct ssh connection ====>
=== with VM2 also ============================>

Now, let us try with VM3 as below:

=== Status of VM3 ====>
vskumar@VM3:~$ cat /etc/hostname
VM3
vskumar@VM3:~$ ssh -V
OpenSSH_7.2p2 Ubuntu-4ubuntu2.2, OpenSSL 1.0.2g 1 Mar 2016
vskumar@VM3:~$
vskumar@VM3:~$ ssh vskumar@192.168.116.135
The authenticity of host ‘192.168.116.135 (192.168.116.135)’ can’t be established.
ECDSA key fingerprint is SHA256:/HtM2RyrOSeFO01WW3d1S5fcB9mBM7MApniY54Nq4k4.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added ‘192.168.116.135’ (ECDSA) to the list of known hosts.
vskumar@192.168.116.135’s password:
Welcome to Ubuntu 16.04.3 LTS (GNU/Linux 4.10.0-28-generic x86_64)

* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage

437 packages can be updated.
251 updates are security updates.

Last login: Sat May 26 07:13:50 2018 from 192.168.116.132
vskumar@VM2:~$ cat /etc/hostname
VM2
vskumar@VM2:~$
vskumar@VM2:~$ ssh vskumar@192.168.116.132
vskumar@192.168.116.132’s password:
Welcome to Ubuntu 16.04.3 LTS (GNU/Linux 4.10.0-28-generic x86_64)

* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage

437 packages can be updated.
251 updates are security updates.

Last login: Sat May 26 07:13:07 2018 from 192.168.116.132
vskumar@ubuntu:~$ cat /etc/hostname
Ans-ControlMachine
vskumar@ubuntu:~$
vskumar@ubuntu:~$ exit
logout
Connection to 192.168.116.132 closed.
vskumar@VM2:~$
vskumar@VM2:~$ exit
logout
Connection to 192.168.116.135 closed.
vskumar@VM3:~$
vskumar@VM3:~$ ssh vskumar@192.168.116.132
The authenticity of host ‘192.168.116.132 (192.168.116.132)’ can’t be established.
ECDSA key fingerprint is SHA256:sIDDAzkiGiTCzpGHOTEU3QbG/oNn4DNvXxHtm7kzAZ4.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added ‘192.168.116.132’ (ECDSA) to the list of known hosts.
vskumar@192.168.116.132’s password:
Welcome to Ubuntu 16.04.3 LTS (GNU/Linux 4.10.0-28-generic x86_64)

* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage

437 packages can be updated.
251 updates are security updates.

Last login: Sat May 26 07:35:04 2018 from 192.168.116.135
vskumar@ubuntu:~$ cat /etc/hostname
Ans-ControlMachine
vskumar@ubuntu:~$ exit
logout
Connection to 192.168.116.132 closed.
vskumar@VM3:~$
== So, we could connect from VM3 ====>
=== To all 3 other VMs ==============>
== The issues is resolved for ssh in VM3 ===>

Now, we are ready to use these ssh connection made machines for Ansible future exercises.

 

In the following video I have demonstrated with trouble shoot methods also:

26.DevOps:How to install Apache-Ant for Ubuntu ?:

Ant-Logo

 

 

In this blog, I would like to demonstrate the Apache-Ant installtion on Ubuntu.

What are the pre-requisites:
You need to have JDK 8/9 in your Ubuntu machine.
If you do not have it please visit my blog to get the installation instructions.
Please go through my JENKINS Instllation blog.
It has JDK installation procedure also.
URL: https://vskumar.blog/2017/11/25/1-devops-jenkins2-9-installation-with-java-9-on-windows-10/

How to uninstall existing ant?:
Step1:
I have ant installed in my ubuntu VM.
1st let me remove it and restart the install process:
We need to use the below command:
sudo apt-get remove ant
===== Screen display =====>
vskumar@ubuntu:~$ sudo apt-get remove ant
[sudo] password for vskumar:
Reading package lists… Done
Building dependency tree
Reading state information… Done
The following packages will be REMOVED:
ant ant-optional
0 upgraded, 0 newly installed, 2 to remove and 4 not upgraded.
After this operation, 3,108 kB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database … 236912 files and directories currently installed.)
Removing ant-optional (1.9.6-1ubuntu1) …
Removing ant (1.9.6-1ubuntu1) …
Processing triggers for man-db (2.7.5-1) …
========= Ant is Removed ===>

Step2:
=== Checking Ant version ===>
vskumar@ubuntu:~$ ant -v
The program ‘ant’ is currently not installed. You can install it by typing:
sudo apt install ant
vskumar@ubuntu:~$ D
===Now there is no Ant setup ===>
Looks like; still the ant is existing.

Step3:
Also please let us note the following:
If we want to delete configuration and/or data files of ant from Ubuntu Xenial completely,
then the below command will work:
sudo apt-get purge ant
== Screen display ===>
vskumar@ubuntu:~$ sudo apt-get purge ant
Reading package lists… Done
Building dependency tree
Reading state information… Done
The following packages will be REMOVED:
ant* ant-optional*
0 upgraded, 0 newly installed, 2 to remove and 4 not upgraded.
After this operation, 3,108 kB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database … 236912 files and directories currently installed.)
Removing ant-optional (1.9.6-1ubuntu1) …
Removing ant (1.9.6-1ubuntu1) …
Processing triggers for man-db (2.7.5-1) …
vskumar@ubuntu:~$
======================>

Now, let us check it.
=== Check the version now also ===>
vskumar@ubuntu:~$
vskumar@ubuntu:~$ ant -v
bash: /usr/bin/ant: No such file or directory
vskumar@ubuntu:~$
=================================>

Still you if you feel ant older version is there, we can follow the below step also:
To delete configuration and/or data files of ant and it’s dependencies from Ubuntu Xenial
then we should execute the below command:
sudo apt-get purge –auto-remove ant

Now, we will see how to install, configure and compile ant latest version1.10.1 ?:

Step1:
We need to update the packages/repos in Ubuntu VM as below:
sudo apt-get update
==== Screen display ======>
vskumar@ubuntu:~$
vskumar@ubuntu:~$ sudo apt-get update
[sudo] password for vskumar:
Hit:1 http://archive.ubuntu.com/ubuntu xenial InRelease
Hit:2 http://ppa.launchpad.net/ansible/ansible/ubuntu xenial InRelease
Hit:3 http://ppa.launchpad.net/webupd8team/java/ubuntu xenial InRelease
Get:4 https://download.docker.com/linux/ubuntu xenial InRelease [65.8 kB]
Ign:5 https://apt.datadoghq.com stable InRelease
Get:6 https://apt.datadoghq.com stable Release [4,525 B]
Get:7 https://apt.datadoghq.com stable Release.gpg [819 B]
Ign:8 https://storebits.docker.com/ee/ubuntu/<subscription-id>/ubuntu xenial InRelease
Ign:9 https://pkg.jenkins.io/debian-stable binary/ InRelease
Ign:10 https://storebits.docker.com/ee/ubuntu/vskumardocker/ubuntu xenial InRelease
Get:11 https://pkg.jenkins.io/debian-stable binary/ Release [2,042 B]
Get:12 https://pkg.jenkins.io/debian-stable binary/ Release.gpg [181 B]
Ign:13 https://storebits.docker.com/ee/ubuntu/<subscription-id>/ubuntu xenial Release
Ign:14 https://storebits.docker.com/ee/ubuntu/vskumardocker/ubuntu xenial Release
Get:15 https://download.docker.com/linux/ubuntu xenial/edge amd64 Packages [4,793 B]
Ign:15 https://download.docker.com/linux/ubuntu xenial/edge amd64 Packages
Ign:16 https://storebits.docker.com/ee/ubuntu/<subscription-id>/ubuntu xenial/test-17.06 amd64 Packages
Ign:17 https://storebits.docker.com/ee/ubuntu/<subscription-id>/ubuntu xenial/test-17.06 all Packages
Ign:18 https://storebits.docker.com/ee/ubuntu/<subscription-id>/ubuntu xenial/test-17.06 Translation-en_US
Ign:19 https://storebits.docker.com/ee/ubuntu/<subscription-id>/ubuntu xenial/test-17.06 Translation-en
Ign:20 https://storebits.docker.com/ee/ubuntu/<subscription-id>/ubuntu xenial/test-17.06 amd64 DEP-11 Metadata
Ign:21 https://storebits.docker.com/ee/ubuntu/<subscription-id>/ubuntu xenial/test-17.06 DEP-11 64×64 Icons
Ign:22 https://storebits.docker.com/ee/ubuntu/vskumardocker/ubuntu xenial/test-17.06 amd64 Packages
Get:23 https://apt.datadoghq.com stable/6 amd64 Packages [2,447 B]
Ign:24 https://storebits.docker.com/ee/ubuntu/vskumardocker/ubuntu xenial/test-17.06 all Packages
Get:15 https://download.docker.com/linux/ubuntu xenial/edge amd64 Packages [4,521 B]
Ign:15 https://download.docker.com/linux/ubuntu xenial/edge amd64 Packages
Ign:25 https://storebits.docker.com/ee/ubuntu/vskumardocker/ubuntu xenial/test-17.06 Translation-en_US
Ign:26 https://storebits.docker.com/ee/ubuntu/vskumardocker/ubuntu xenial/test-17.06 Translation-en
Ign:27 https://storebits.docker.com/ee/ubuntu/vskumardocker/ubuntu xenial/test-17.06 amd64 DEP-11 Metadata
Ign:28 https://storebits.docker.com/ee/ubuntu/vskumardocker/ubuntu xenial/test-17.06 DEP-11 64×64 Icons
Ign:16 https://storebits.docker.com/ee/ubuntu/<subscription-id>/ubuntu xenial/test-17.06 amd64 Packages
Ign:17 https://storebits.docker.com/ee/ubuntu/<subscription-id>/ubuntu xenial/test-17.06 all Packages
Ign:18 https://storebits.docker.com/ee/ubuntu/<subscription-id>/ubuntu xenial/test-17.06 Translation-en_US
Ign:19 https://storebits.docker.com/ee/ubuntu/<subscription-id>/ubuntu xenial/test-17.06 Translation-en
Get:15 https://download.docker.com/linux/ubuntu xenial/edge amd64 Packages [29.9 kB]
Ign:20 https://storebits.docker.com/ee/ubuntu/<subscription-id>/ubuntu xenial/test-17.06 amd64 DEP-11 Metadata
Ign:21 https://storebits.docker.com/ee/ubuntu/<subscription-id>/ubuntu xenial/test-17.06 DEP-11 64×64 Icons
Ign:22 https://storebits.docker.com/ee/ubuntu/vskumardocker/ubuntu xenial/test-17.06 amd64 Packages
Ign:24 https://storebits.docker.com/ee/ubuntu/vskumardocker/ubuntu xenial/test-17.06 all Packages
Ign:25 https://storebits.docker.com/ee/ubuntu/vskumardocker/ubuntu xenial/test-17.06 Translation-en_US
Ign:26 https://storebits.docker.com/ee/ubuntu/vskumardocker/ubuntu xenial/test-17.06 Translation-en
Get:29 https://pkg.jenkins.io/debian-stable binary/ Packages [12.7 kB]
Ign:29 https://pkg.jenkins.io/debian-stable binary/ Packages
Ign:27 https://storebits.docker.com/ee/ubuntu/vskumardocker/ubuntu xenial/test-17.06 amd64 DEP-11 Metadata
Ign:28 https://storebits.docker.com/ee/ubuntu/vskumardocker/ubuntu xenial/test-17.06 DEP-11 64×64 Icons
Ign:16 https://storebits.docker.com/ee/ubuntu/<subscription-id>/ubuntu xenial/test-17.06 amd64 Packages
Ign:17 https://storebits.docker.com/ee/ubuntu/<subscription-id>/ubuntu xenial/test-17.06 all Packages
Ign:18 https://storebits.docker.com/ee/ubuntu/<subscription-id>/ubuntu xenial/test-17.06 Translation-en_US
Ign:19 https://storebits.docker.com/ee/ubuntu/<subscription-id>/ubuntu xenial/test-17.06 Translation-en
Ign:20 https://storebits.docker.com/ee/ubuntu/<subscription-id>/ubuntu xenial/test-17.06 amd64 DEP-11 Metadata
Ign:21 https://storebits.docker.com/ee/ubuntu/<subscription-id>/ubuntu xenial/test-17.06 DEP-11 64×64 Icons
Get:29 https://pkg.jenkins.io/debian-stable binary/ Packages [11.9 kB]
Ign:22 https://storebits.docker.com/ee/ubuntu/vskumardocker/ubuntu xenial/test-17.06 amd64 Packages
Ign:24 https://storebits.docker.com/ee/ubuntu/vskumardocker/ubuntu xenial/test-17.06 all Packages
Ign:25 https://storebits.docker.com/ee/ubuntu/vskumardocker/ubuntu xenial/test-17.06 Translation-en_US
Ign:26 https://storebits.docker.com/ee/ubuntu/vskumardocker/ubuntu xenial/test-17.06 Translation-en
Ign:27 https://storebits.docker.com/ee/ubuntu/vskumardocker/ubuntu xenial/test-17.06 amd64 DEP-11 Metadata
Ign:28 https://storebits.docker.com/ee/ubuntu/vskumardocker/ubuntu xenial/test-17.06 DEP-11 64×64 Icons
Ign:16 https://storebits.docker.com/ee/ubuntu/<subscription-id>/ubuntu xenial/test-17.06 amd64 Packages
Ign:17 https://storebits.docker.com/ee/ubuntu/<subscription-id>/ubuntu xenial/test-17.06 all Packages
Ign:18 https://storebits.docker.com/ee/ubuntu/<subscription-id>/ubuntu xenial/test-17.06 Translation-en_US
Ign:19 https://storebits.docker.com/ee/ubuntu/<subscription-id>/ubuntu xenial/test-17.06 Translation-en
Ign:20 https://storebits.docker.com/ee/ubuntu/<subscription-id>/ubuntu xenial/test-17.06 amd64 DEP-11 Metadata
Ign:21 https://storebits.docker.com/ee/ubuntu/<subscription-id>/ubuntu xenial/test-17.06 DEP-11 64×64 Icons
Ign:22 https://storebits.docker.com/ee/ubuntu/vskumardocker/ubuntu xenial/test-17.06 amd64 Packages
Ign:24 https://storebits.docker.com/ee/ubuntu/vskumardocker/ubuntu xenial/test-17.06 all Packages
Ign:25 https://storebits.docker.com/ee/ubuntu/vskumardocker/ubuntu xenial/test-17.06 Translation-en_US
Ign:26 https://storebits.docker.com/ee/ubuntu/vskumardocker/ubuntu xenial/test-17.06 Translation-en
Ign:27 https://storebits.docker.com/ee/ubuntu/vskumardocker/ubuntu xenial/test-17.06 amd64 DEP-11 Metadata
Ign:28 https://storebits.docker.com/ee/ubuntu/vskumardocker/ubuntu xenial/test-17.06 DEP-11 64×64 Icons
Ign:16 https://storebits.docker.com/ee/ubuntu/<subscription-id>/ubuntu xenial/test-17.06 amd64 Packages
Ign:17 https://storebits.docker.com/ee/ubuntu/<subscription-id>/ubuntu xenial/test-17.06 all Packages
Ign:18 https://storebits.docker.com/ee/ubuntu/<subscription-id>/ubuntu xenial/test-17.06 Translation-en_US
Ign:19 https://storebits.docker.com/ee/ubuntu/<subscription-id>/ubuntu xenial/test-17.06 Translation-en
Ign:20 https://storebits.docker.com/ee/ubuntu/<subscription-id>/ubuntu xenial/test-17.06 amd64 DEP-11 Metadata
Ign:21 https://storebits.docker.com/ee/ubuntu/<subscription-id>/ubuntu xenial/test-17.06 DEP-11 64×64 Icons
Ign:22 https://storebits.docker.com/ee/ubuntu/vskumardocker/ubuntu xenial/test-17.06 amd64 Packages
Ign:24 https://storebits.docker.com/ee/ubuntu/vskumardocker/ubuntu xenial/test-17.06 all Packages
Ign:25 https://storebits.docker.com/ee/ubuntu/vskumardocker/ubuntu xenial/test-17.06 Translation-en_US
Ign:26 https://storebits.docker.com/ee/ubuntu/vskumardocker/ubuntu xenial/test-17.06 Translation-en
Ign:27 https://storebits.docker.com/ee/ubuntu/vskumardocker/ubuntu xenial/test-17.06 amd64 DEP-11 Metadata
Ign:28 https://storebits.docker.com/ee/ubuntu/vskumardocker/ubuntu xenial/test-17.06 DEP-11 64×64 Icons
Err:16 https://storebits.docker.com/ee/ubuntu/<subscription-id>/ubuntu xenial/test-17.06 amd64 Packages
403 Forbidden
Ign:17 https://storebits.docker.com/ee/ubuntu/<subscription-id>/ubuntu xenial/test-17.06 all Packages
Ign:18 https://storebits.docker.com/ee/ubuntu/<subscription-id>/ubuntu xenial/test-17.06 Translation-en_US
Ign:19 https://storebits.docker.com/ee/ubuntu/<subscription-id>/ubuntu xenial/test-17.06 Translation-en
Ign:20 https://storebits.docker.com/ee/ubuntu/<subscription-id>/ubuntu xenial/test-17.06 amd64 DEP-11 Metadata
Ign:21 https://storebits.docker.com/ee/ubuntu/<subscription-id>/ubuntu xenial/test-17.06 DEP-11 64×64 Icons
Err:22 https://storebits.docker.com/ee/ubuntu/vskumardocker/ubuntu xenial/test-17.06 amd64 Packages
403 Forbidden
Ign:24 https://storebits.docker.com/ee/ubuntu/vskumardocker/ubuntu xenial/test-17.06 all Packages
Ign:25 https://storebits.docker.com/ee/ubuntu/vskumardocker/ubuntu xenial/test-17.06 Translation-en_US
Ign:26 https://storebits.docker.com/ee/ubuntu/vskumardocker/ubuntu xenial/test-17.06 Translation-en
Ign:27 https://storebits.docker.com/ee/ubuntu/vskumardocker/ubuntu xenial/test-17.06 amd64 DEP-11 Metadata
Ign:28 https://storebits.docker.com/ee/ubuntu/vskumardocker/ubuntu xenial/test-17.06 DEP-11 64×64 Icons
Fetched 118 kB in 35s (3,328 B/s)
Reading package lists… Done
W: The repository ‘https://storebits.docker.com/ee/ubuntu/<subscription-id>/ubuntu xenial Release’ does not have a Release file.
N: Data from such a repository can’t be authenticated and is therefore potentially dangerous to use.
N: See apt-secure(8) manpage for repository creation and user configuration details.
W: The repository ‘https://storebits.docker.com/ee/ubuntu/vskumardocker/ubuntu xenial Release’ does not have a Release file.
N: Data from such a repository can’t be authenticated and is therefore potentially dangerous to use.
N: See apt-secure(8) manpage for repository creation and user configuration details.
E: Failed to fetch https://storebits.docker.com/ee/ubuntu/<subscription-id>/ubuntu/dists/xenial/test-17.06/binary-amd64/Packages 403 Forbidden
E: Failed to fetch https://storebits.docker.com/ee/ubuntu/vskumardocker/ubuntu/dists/xenial/test-17.06/binary-amd64/Packages 403 Forbidden
E: Some index files failed to download. They have been ignored, or old ones used instead.
vskumar@ubuntu:~$
====================================>

Step2:
Now, We can get the install file of ant with the below command:
sudo apt-get install ant
==== Screen Display =====>
vskumar@ubuntu:~$
vskumar@ubuntu:~$ sudo apt-get install ant
Reading package lists… Done
Building dependency tree
Reading state information… Done
The following additional packages will be installed:
ant-optional
Suggested packages:
ant-doc ant-gcj default-jdk | java-compiler | java-sdk ant-optional-gcj
antlr javacc jython libbcel-java libbsf-java libgnumail-java libjdepend-java
liboro-java libregexp-java
The following NEW packages will be installed:
ant ant-optional
0 upgraded, 2 newly installed, 0 to remove and 4 not upgraded.
Need to get 0 B/2,205 kB of archives.
After this operation, 3,108 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Selecting previously unselected package ant.
(Reading database … 236678 files and directories currently installed.)
Preparing to unpack …/ant_1.9.6-1ubuntu1_all.deb …
Unpacking ant (1.9.6-1ubuntu1) …
Selecting previously unselected package ant-optional.
Preparing to unpack …/ant-optional_1.9.6-1ubuntu1_all.deb …
Unpacking ant-optional (1.9.6-1ubuntu1) …
Processing triggers for man-db (2.7.5-1) …
Setting up ant (1.9.6-1ubuntu1) …
Setting up ant-optional (1.9.6-1ubuntu1) …
vskumar@ubuntu:~$
==========================>

Step3:
Now let me check its version.
===== Version check ===>
vskumar@ubuntu:~$ ant -v
Apache Ant(TM) version 1.9.6 compiled on July 8 2015
Trying the default build file: build.xml
Buildfile: build.xml does not exist!
Build failed
vskumar@ubuntu:~$
====================>

Step4:
We need to Install Apache Ant on Ubuntu 16.04 using SDKMan.
SDKMAN is a tool which can be usd to manage parallel versions of multiple
Software Development Kits on most Unix based systems.
The same way, we can leverage SDKMAN to install Apache Ant on Ubuntu 16.04.
Using the below command:
sdk install ant
Before doing this I need to install SDK in my ubuntu VM.

===== Screen display =====>
vskumar@ubuntu:~$
vskumar@ubuntu:~$ curl -s “https://get.sdkman.io&#8221; | bash

-+syyyyyyys:
`/yho:` -yd.
`/yh/` +m.
.oho. hy .`
.sh/` :N` `-/o` `+dyyo:.
.yh:` `M- `-/osysoym :hs` `-+sys: hhyssssssssy+
.sh:` `N: ms/-“ yy.yh- -hy. `.N-““““+N.
`od/` `N- -/oM- ddd+` `sd: hNNm -N:
:do` .M. dMMM- `ms. /d+` `NMMs `do
.yy- :N` “`mMMM. – -hy. /MMM: yh
`+d+` `:/oo/` `-/osyh/ossssssdNMM` .sh: yMMN` /m.
-dh- :ymNMMMMy `-/shmNm-`:N/-.“ `.sN /N- `NMMy .m/
`oNs` -hysosmMMMMydmNmds+-.:ohm : sd` :MMM/ yy
.hN+ /d: -MMMmhs/-.` .MMMh .ss+- `yy` sMMN` :N.
:mN/ `N/ `o/-` :MMMo +MMMN- .` `ds mMMh do
/NN/ `N+….–:/+oooosooo+:sMMM: hMMMM: `my .m+ -MMM+ :N.
/NMo -+ooooo+/:-….`…:+hNMN. `NMMMd` .MM/ -m: oMMN. hs
-NMd` :mm -MMMm- .s/ -MMm. /m- mMMd -N.
`mMM/ .- /MMh. -dMo -MMMy od. .MMMs..—yh
+MMM. sNo`.sNMM+ :MMMM/ sh`+MMMNmNm+++-
mMMM- /–ohmMMM+ :MMMMm. `hyymmmdddo
MMMMh. ““ `-+yy/`yMMM/ :MMMMMy -sm:.“..-:-.`
dMMMMmo-.“““..-:/osyhddddho. `+shdh+. hMMM: :MmMMMM/ ./yy/` `:sys+/+sh/
.dMMMMMMmdddddmmNMMMNNNNNMMMMMs sNdo- dMMM- `-/yd/MMMMm-:sy+. :hs- /N`
`/ymNNNNNNNmmdys+/::—-/dMMm: +m- mMMM+ohmo/.` sMMMMdo- .om: `sh
`.—–+/.` `.-+hh/` `od. NMMNmds/ `mmy:` +mMy `:yy.
/moyso+//+ossso:. .yy` `dy+:` .. :MMMN+—/oys:
/+m: `.-:::-` /d+ +MMMMMMMNh:`
+MN/ -yh. `+hddhy+.
/MM+ .sh:
:NMo -sh/
-NMs `/yy:
.NMy `:sh+.
`mMm` ./yds-
`dMMMmyo:-.““.-:oymNy:`
+NMMMMMMMMMMMMMMMMms:`
-+shmNMMMNmdy+:`

Now attempting installation…

Looking for a previous installation of SDKMAN…
Looking for unzip…
Looking for zip…
Looking for curl…
Looking for sed…
Installing SDKMAN scripts…
Create distribution directories…
Getting available candidates…
Prime the config file…
Download script archive…
######################################################################## 100.0%
Extract script archive…
Install scripts…
Set version to 5.6.3+299 …
Attempt update of interactive bash profile on regular UNIX…
Added sdkman init snippet to /home/vskumar/.bashrc
Attempt update of zsh profile…
Updated existing /home/vskumar/.zshrc

All done!

Please open a new terminal, or run the following in the existing one:

source “/home/vskumar/.sdkman/bin/sdkman-init.sh”

Then issue the following command:

sdk help

Enjoy!!!
vskumar@ubuntu:~$
== SDK installed =====>
We need to use the below command:
=====>
vskumar@ubuntu:~$ source “$HOME/.sdkman/bin/sdkman-init.sh”
vskumar@ubuntu:~$
======>

Now, let us check SDK Version.
===== SDK Version checking ====>
vskumar@ubuntu:~$ sdk version
==== BROADCAST =================================================================
* 09/05/18: sbt 1.1.5 released on SDKMAN! #scala
* 09/05/18: Springboot 2.0.2.RELEASE released on SDKMAN! #springboot
* 09/05/18: Springboot 1.5.13.RELEASE released on SDKMAN! #springboot
================================================================================

SDKMAN 5.6.3+299
vskumar@ubuntu:~$
==========================>

Step5:

Now, let us use the below command:
sdk install ant

=== Screen display ==>
vskumar@ubuntu:~$
vskumar@ubuntu:~$ sdk install ant

 

Downloading: ant 1.10.1

In progress…

######################################################################## 100.0%

Installing: ant 1.10.1
Done installing!

 

Setting ant 1.10.1 as default.
vskumar@ubuntu:~$
vskumar@ubuntu:~$
=================>

Step6:
Now, let us check the ant’s latest version:

== Screen display ===>
vskumar@ubuntu:~$ ant -v
Apache Ant(TM) version 1.10.1 compiled on February 2 2017
Trying the default build file: build.xml
Buildfile: build.xml does not exist!
Build failed
vskumar@ubuntu:~$
== Now version change you can see after SDK usage ===>

Step7:
How to Create ANT_HOME Environment Variables?:

Create an ant.sh file at /etc/profile.d folder (you can use vi with below command)

== Let us see the files===>
vskumar@ubuntu:~$ pwd
/home/vskumar
vskumar@ubuntu:~$ ls /etc/profile.d
appmenu-qt5.sh bash_completion.sh vte-2.91.sh
apps-bin-path.sh cedilla-portuguese.sh
vskumar@ubuntu:~$
==========================>
There is no ant.sh file.

sudo vi /etc/profile.d/ant.sh
Enter the follow content to the file:

export ANT_HOME=/usr/local/ant
export PATH=${ANT_HOME}/bin:${PATH}
Save the file.
====== ant.sh file creation ===>
vskumar@ubuntu:~$ sudo vim /etc/profile.d/ant.sh
vskumar@ubuntu:~$
vskumar@ubuntu:~$ sudo cat /etc/profile.d/ant.sh

export ANT_HOME=/usr/local/ant
export PATH=${ANT_HOME}/bin:${PATH}
vskumar@ubuntu:~$
vskumar@ubuntu:~$ ls /etc/profile.d
ant.sh apps-bin-path.sh cedilla-portuguese.sh
appmenu-qt5.sh bash_completion.sh vte-2.91.sh
vskumar@ubuntu:~$
============ Contents of ant.sh=====>

Step8:
We need to activate the above environment variables.
We can do that by log out and log in again or simply run below command:
source /etc/profile
==== Screen display ===>
vskumar@ubuntu:~$ source /etc/profile
vskumar@ubuntu:~$
=======================>

Now let us check the ant version after doing the above steps to observe the change:

==== Display ==>
vskumar@ubuntu:~$
vskumar@ubuntu:~$ ant -version
Apache Ant(TM) version 1.10.1 compiled on February 2 2017
vskumar@ubuntu:~$
== Now error now =====>

Finally, we have configured Apache Ant(TM) version 1.10.1 and compiled successfully.

For Ant installation on windows 10 visit my blog:

https://vskumar.blog/2018/05/12/24-devops-how-to-install-apache-ant-for-windows-10/

25.DevOps:How to install Apache-Maven for Windows 10 ?

Apache-Maven Logo

With reference to my previous blog for Maven installation on Ubuntu:
https://vskumar.blog/2018/05/05/21-devops-how-to-install-maven-3-3-9-on-ubuntu-linux/

In this blog, I have shown the steps for Maven installation on
Windows 10.

Step1:
Goto the site: http://maven.apache.org/download.cgi
You can find the file: apache-maven-3.5.3-bin.zip
Save it to your desired location.

Step2:
Unzip it and it show have created the folder as below:
E:\apache-maven-3.5.3-bin

Note: You can replace this folder path with your Maven path.

It should have the following files/folders:

E:\apache-maven-3.5.3-bin>dir/p
Volume in drive E is New Volume
Volume Serial Number is 1870-3E6A

Directory of E:\apache-maven-3.5.3-bin

05/12/2018 01:40 PM <DIR> .
05/12/2018 01:40 PM <DIR> ..
05/12/2018 01:40 PM <DIR> apache-maven-3.5.3
0 File(s) 0 bytes
3 Dir(s) 33,347,407,872 bytes free

E:\apache-maven-3.5.3-bin>
E:\apache-maven-3.5.3-bin>cd apache*
E:\apache-maven-3.5.3-bin\apache-maven-3.5.3>
E:\apache-maven-3.5.3-bin\apache-maven-3.5.3>dir/p
Volume in drive E is New Volume
Volume Serial Number is 1870-3E6A

Directory of E:\apache-maven-3.5.3-bin\apache-maven-3.5.3

05/12/2018 01:40 PM <DIR> .
05/12/2018 01:40 PM <DIR> ..
05/12/2018 01:40 PM <DIR> bin
05/12/2018 01:40 PM <DIR> boot
05/12/2018 01:40 PM <DIR> conf
05/12/2018 01:40 PM <DIR> lib
05/12/2018 01:40 PM 20,959 LICENSE
05/12/2018 01:40 PM 182 NOTICE
05/12/2018 01:40 PM 2,544 README.txt
3 File(s) 23,685 bytes
6 Dir(s) 33,347,407,872 bytes free

E:\apache-maven-3.5.3-bin\apache-maven-3.5.3>

Step3:
Let us update the windows system/environment variables:

Check for M2_HOME variable. If it is not there,
create a new one and add the below:
Variable Name : M2_HOME
Variable Value : E:\apache-maven-3.5.3-bin\apache-maven-3.5.3

In your system variables,
if you have MAVEN_HOME as avriable you need update its value also.
Now, append this path to your PATH variable also.

Step4:
Now, how to verify the installed Maven version ?:
Open a fresh windows command prompt.
Type mvn -version
You should see the screen output as below wuth its 3.5.3 version:
Microsoft Windows [Version 10.0.16299.431]
(c) 2017 Microsoft Corporation. All rights reserved.

C:\Users\Toshiba>mvn -version
Apache Maven 3.5.3 (3383c37e1f9e9b3bc3df5050c29c8aff9f295297; 2018-02-25T01:19:05+05:30)
Maven home: E:\apache-maven-3.5.3-bin\apache-maven-3.5.3
Java version: 9.0.1, vendor: Oracle Corporation
Java home: D:\Java\jdk-9.0.1
Default locale: en_US, platform encoding: Cp1252
OS name: “windows 10”, version: “10.0”, arch: “amd64”, family: “windows”

C:\Users\Toshiba>

If you are getting the above version display;

So it means you have the correct/latest Maven version in your machine.

 

23.DevOps: How to install Ansible on Ubuntu [Linux] VM ?

 

ansible-logo.png

In this blog, I would like to demonstrate  “Installing Ansible on Ubuntu VM”.

At the End of this blog you can see the demonstrated Video.

Let us follow the below steps:

Step 1:
To get Ansible for Ubuntu is to add the project’s PPA (personal package archive) to ubuntu system.
We can add the Ansible PPA by typing the following command:

$sudo apt-add-repository ppa:ansible/ansible

=== Screen output ====>
vskumar@ubuntu:~$
vskumar@ubuntu:~$ sudo apt-add-repository ppa:ansible/ansible
[sudo] password for vskumar:
Ansible is a radically simple IT automation platform that makes your applications and systems easier to deploy.
Avoid writing scripts or custom code to deploy and update your applications— automate in a language that
approaches plain English, using SSH, with no agents to install on remote systems.

http://ansible.com/
More info: https://launchpad.net/~ansible/+archive/ubuntu/ansible
Press [ENTER] to continue or ctrl-c to cancel adding it

gpg: keyring `/tmp/tmpzhb6yoiy/secring.gpg’ created
gpg: keyring `/tmp/tmpzhb6yoiy/pubring.gpg’ created
gpg: requesting key 7BB9C367 from hkp server keyserver.ubuntu.com
gpg: /tmp/tmpzhb6yoiy/trustdb.gpg: trustdb created
gpg: key 7BB9C367: public key “Launchpad PPA for Ansible, Inc.” imported
gpg: Total number processed: 1
gpg: imported: 1 (RSA: 1)
OK
vskumar@ubuntu:~$
========= Added Ansible to PPA ===>
Step 2:
Now, let us refresh ubuntu [VM] system package index, so that it is aware of the packages available in the PPA.
Then, we can install the software.
We need to follow the below commands:
$sudo apt-get update
$sudo apt-get install ansible
==== Update package=======>
vskumar@ubuntu:~$ sudo apt-get update
Get:1 http://ppa.launchpad.net/ansible/ansible/ubuntu xenial InRelease [18.0 kB]
Hit:2 https://download.docker.com/linux/ubuntu xenial InRelease
Hit:3 http://archive.ubuntu.com/ubuntu xenial InRelease
Hit:4 http://ppa.launchpad.net/webupd8team/java/ubuntu xenial InRelease
Get:5 http://ppa.launchpad.net/ansible/ansible/ubuntu xenial/main amd64 Packages [540 B]
Ign:6 https://pkg.jenkins.io/debian-stable binary/ InRelease
Get:7 http://ppa.launchpad.net/ansible/ansible/ubuntu xenial/main i386 Packages [540 B]
Hit:8 https://pkg.jenkins.io/debian-stable binary/ Release
Get:10 http://ppa.launchpad.net/ansible/ansible/ubuntu xenial/main Translation-en [344 B]
Fetched 19.5 kB in 2s (7,857 B/s)
Reading package lists… Done
vskumar@ubuntu:~$
===== Updated =====>

Step 3:
Now, let us install Ansible as below:
==== Installing Ansible =====>
vskumar@ubuntu:~$ sudo apt-get install ansible
Reading package lists… Done
Building dependency tree
Reading state information… Done
The following additional packages will be installed:
python-ecdsa python-httplib2 python-jinja2 python-markupsafe python-paramiko
sshpass
Suggested packages:
python-jinja2-doc
The following NEW packages will be installed:
ansible python-ecdsa python-httplib2 python-jinja2 python-markupsafe
python-paramiko sshpass
0 upgraded, 7 newly installed, 0 to remove and 0 not upgraded.
Need to get 3,001 kB of archives.
After this operation, 24.1 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://archive.ubuntu.com/ubuntu xenial/main amd64 python-markupsafe amd64 0.23-2build2 [15.5 kB]
Get:2 http://ppa.launchpad.net/ansible/ansible/ubuntu xenial/main amd64 ansible all 2.4.3.0-1ppa~xenial [2,690 kB]
Get:3 http://archive.ubuntu.com/ubuntu xenial/main amd64 python-jinja2 all 2.8-1 [109 kB]
Get:4 http://archive.ubuntu.com/ubuntu xenial/main amd64 python-ecdsa all 0.13-2 [34.0 kB]
Get:5 http://archive.ubuntu.com/ubuntu xenial/main amd64 python-paramiko all 1.16.0-1 [109 kB]
Get:6 http://archive.ubuntu.com/ubuntu xenial/main amd64 python-httplib2 all 0.9.1+dfsg-1 [34.2 kB]
Get:7 http://archive.ubuntu.com/ubuntu xenial/universe amd64 sshpass amd64 1.05-1 [10.5 kB]
Fetched 3,001 kB in 9s (306 kB/s)
Selecting previously unselected package python-markupsafe.
(Reading database … 218383 files and directories currently installed.)
Preparing to unpack …/python-markupsafe_0.23-2build2_amd64.deb …
Unpacking python-markupsafe (0.23-2build2) …
Selecting previously unselected package python-jinja2.
Preparing to unpack …/python-jinja2_2.8-1_all.deb …
Unpacking python-jinja2 (2.8-1) …
Selecting previously unselected package python-ecdsa.
Preparing to unpack …/python-ecdsa_0.13-2_all.deb …
Unpacking python-ecdsa (0.13-2) …
Selecting previously unselected package python-paramiko.
Preparing to unpack …/python-paramiko_1.16.0-1_all.deb …
Unpacking python-paramiko (1.16.0-1) …
Selecting previously unselected package python-httplib2.
Preparing to unpack …/python-httplib2_0.9.1+dfsg-1_all.deb …
Unpacking python-httplib2 (0.9.1+dfsg-1) …
Selecting previously unselected package sshpass.
Preparing to unpack …/sshpass_1.05-1_amd64.deb …
Unpacking sshpass (1.05-1) …
Selecting previously unselected package ansible.
Preparing to unpack …/ansible_2.4.3.0-1ppa~xenial_all.deb …
Unpacking ansible (2.4.3.0-1ppa~xenial) …
Processing triggers for man-db (2.7.5-1) …
Setting up python-markupsafe (0.23-2build2) …
Setting up python-jinja2 (2.8-1) …
Setting up python-ecdsa (0.13-2) …
Setting up python-paramiko (1.16.0-1) …
Setting up python-httplib2 (0.9.1+dfsg-1) …
Setting up sshpass (1.05-1) …
Setting up ansible (2.4.3.0-1ppa~xenial) …
vskumar@ubuntu:~$
=== Ansible installation is done! ====>

Step 4:
Let us add the below python properties  also:

sudo apt-get install python-software-properties
== Installing python properties =======>
vskumar@ubuntu:/etc/ansible$ sudo apt-get install python-software-properties
Reading package lists… Done
Building dependency tree
Reading state information… Done
The following additional packages will be installed:
python-apt python-pycurl
Suggested packages:
python-apt-dbg python-apt-doc libcurl4-gnutls-dev python-pycurl-dbg
python-pycurl-doc
The following NEW packages will be installed:
python-apt python-pycurl python-software-properties
0 upgraded, 3 newly installed, 0 to remove and 0 not upgraded.
Need to get 202 kB of archives.
After this operation, 927 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://archive.ubuntu.com/ubuntu xenial/main amd64 python-apt amd64 1.1.0~beta1build1 [139 kB]
Get:2 http://archive.ubuntu.com/ubuntu xenial/main amd64 python-pycurl amd64 7.43.0-1ubuntu1 [43.3 kB]
Get:3 http://archive.ubuntu.com/ubuntu xenial/universe amd64 python-software-properties all 0.96.20 [20.1 kB]
Fetched 202 kB in 1s (181 kB/s)
Selecting previously unselected package python-apt.
(Reading database … 220895 files and directories currently installed.)
Preparing to unpack …/python-apt_1.1.0~beta1build1_amd64.deb …
Unpacking python-apt (1.1.0~beta1build1) …
Selecting previously unselected package python-pycurl.
Preparing to unpack …/python-pycurl_7.43.0-1ubuntu1_amd64.deb …
Unpacking python-pycurl (7.43.0-1ubuntu1) …
Selecting previously unselected package python-software-properties.
Preparing to unpack …/python-software-properties_0.96.20_all.deb …
Unpacking python-software-properties (0.96.20) …
Setting up python-apt (1.1.0~beta1build1) …
Setting up python-pycurl (7.43.0-1ubuntu1) …
Setting up python-software-properties (0.96.20) …
vskumar@ubuntu:/etc/ansible$
===== Installed python properties ======>

Step 5:
Let us check the version:
=== Checking ANSIBLE Version ===>
vskumar@ubuntu:~$ ansible –version
ansible 2.4.3.0
config file = /etc/ansible/ansible.cfg
configured module search path = [u’/home/vskumar/.ansible/plugins/modules’, u’/usr/share/ansible/plugins/modules’]
ansible python module location = /usr/lib/python2.7/dist-packages/ansible
executable location = /usr/bin/ansible
python version = 2.7.12 (default, Dec 4 2017, 14:50:18) [GCC 5.4.0 20160609]
vskumar@ubuntu:~$
=============================>
It means from the above display it is confirmed ansible is available.

Step 6:
The ansible is on the below dir:

======= Check List of files ===>
vskumar@ubuntu:~$ ls -lha /etc/ansible
total 48K
drwxr-xr-x 4 root root 4.0K Mar 6 08:52 .
drwxr-xr-x 142 root root 12K Mar 6 05:59 ..
-rw-r–r– 1 root root 19K Jan 31 15:21 ansible.cfg
drwxr-xr-x 2 root root 4.0K Mar 6 08:59 group_vars
-rw-r–r– 1 root root 1.2K Mar 6 08:20 hosts
drwxr-xr-x 2 root root 4.0K Jan 31 19:46 roles
vskumar@ubuntu:~$
========================>

Step 7:
Always it is better we need to have backup of the above files in a folder.
Now let me copy all of them as below:
Make a backup of all the files as below :
== Making backup ====>

vskumar@ubuntu:~$ sudo cp -R /etc/ansible ansplatform1

vskumar@ubuntu:~$ cd ansplatform1
vskumar@ubuntu:~/ansplatform1$ ls
ansible.cfg group_vars hosts roles
vskumar@ubuntu:~/ansplatform1$
===== Backup files ====>

Step 8:
In the above dir, let us modify ansible.cfg
to have the below line uncommented:
inventory = hosts
====Modifying ansible.cfg ====>
vskumar@ubuntu:~/ansplatform1$ sudo vim ansible.cfg
vskumar@ubuntu:~/ansplatform1$
======>

You can see part of the file as below :
=== Part of config file to update ====>
vskumar@ubuntu:/etc/ansible$ ls
ansible.cfg group_vars hosts roles
vskumar@ubuntu:/etc/ansible$ vim ansible
vskumar@ubuntu:/etc/ansible$
vskumar@ubuntu:/etc/ansible$ vim ansible.cfg
vskumar@ubuntu:/etc/ansible$

Updated line:
inventory = /etc/ansible/hosts

== Updated area only ===>

Step 9:

Configuring Ansible Hosts:
Ansible keeps track of all of the servers.
It knows about them through a “hosts” file.
We need to set up this file first, before we can begin to
communicate with our other computers.
Now let us see the current content of hosts file:
Using : $sudo cat /etc/ansible/hosts

====== The default Contents of hosts file ===>
vskumar@ubuntu:~$ sudo cat /etc/ansible/hosts
# This is the default ansible ‘hosts’ file.
#
# It should live in /etc/ansible/hosts
#
# – Comments begin with the ‘#’ character
# – Blank lines are ignored
# – Groups of hosts are delimited by [header] elements
# – You can enter hostnames or ip addresses
# – A hostname/ip can be a member of multiple groups

# Ex 1: Ungrouped hosts, specify before any group headers.

## green.example.com
## blue.example.com
## 192.168.100.1
## 192.168.100.10

# Ex 2: A collection of hosts belonging to the ‘webservers’ group

## [webservers]
## alpha.example.org
## beta.example.org
## 192.168.1.100
## 192.168.1.110

# If you have multiple hosts following a pattern you can specify
# them like this:

## www[001:006].example.com

# Ex 3: A collection of database servers in the ‘dbservers’ group

## [dbservers]
##
## db01.intranet.mydomain.net
## db02.intranet.mydomain.net
## 10.25.1.56
## 10.25.1.57

# Here’s another example of host ranges, this time there are no
# leading 0s:

## db-[99:101]-node.example.com

vskumar@ubuntu:~$
==================>

We can see a file that has a lot of example configurations,
none of them will actually work for us since these hosts are made up.
So to start with, let’s make sure they all are commented out on the
lines in this file by adding a “#” before each line.

We will keep these examples in the file only as they were to help us with
configuration.

If we want to implement more complex scenarios in the future these can be reused.

After making sure all of these lines are commented,
we can start adding our hosts in the hosts file.
To do our lab exercise;
Now, we need to identify our local hosts.
You can check your laptop or desktop ip as one host.
Another host you consider your ubuntu VM, where the current Ansible is configured.
For now, let us work with two hosts only.
In my systems:
To identify my ubuntu host1:
====== ifconfig =====>

vskumar@ubuntu:~$ ifconfig
docker0 Link encap:Ethernet HWaddr 02:42:06:95:ca:2d
inet addr:172.17.0.1 Bcast:172.17.255.255 Mask:255.255.0.0
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

ens33 Link encap:Ethernet HWaddr 00:0c:29:f8:40:61
inet addr:192.168.116.129 Bcast:192.168.116.255 Mask:255.255.255.0
inet6 addr: fe80::2fed:4aa:a6:34ad/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:3621 errors:0 dropped:0 overruns:0 frame:0
TX packets:1342 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:5111534 (5.1 MB) TX bytes:112090 (112.0 KB)

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:530 errors:0 dropped:0 overruns:0 frame:0
TX packets:530 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:47656 (47.6 KB) TX bytes:47656 (47.6 KB)

vskumar@ubuntu:~$
=======================>
I need to consider  my base ubuntu VM is as ‘192.168.116.129’
Hence my host1=192.168.116.129 from ens33
You can also check your VM IP.

Now, let me check my local host [laptop] ip:

====== IPCONFIG info from Laptop CMD =====>
Connection-specific DNS Suffix . :
Link-local IPv6 Address . . . . . : fe80::197c:6a85:f86:a3e4%20
IPv4 Address. . . . . . . . . . . : 192.168.137.1
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . :
======================>
Let me check the ip connection from my Ubuntu VM.
=== Testing laptop ip from VM ====>
vskumar@ubuntu:~$ ping 192.168.137.1
PING 192.168.137.1 (192.168.137.1) 56(84) bytes of data.
64 bytes from 192.168.137.1: icmp_seq=1 ttl=128 time=3.89 ms
64 bytes from 192.168.137.1: icmp_seq=2 ttl=128 time=1.15 ms
64 bytes from 192.168.137.1: icmp_seq=3 ttl=128 time=1.19 ms
64 bytes from 192.168.137.1: icmp_seq=4 ttl=128 time=1.38 ms
64 bytes from 192.168.137.1: icmp_seq=5 ttl=128 time=1.15 ms
64 bytes from 192.168.137.1: icmp_seq=6 ttl=128 time=1.26 ms
64 bytes from 192.168.137.1: icmp_seq=7 ttl=128 time=1.13 ms
64 bytes from 192.168.137.1: icmp_seq=8 ttl=128 time=1.13 ms
64 bytes from 192.168.137.1: icmp_seq=9 ttl=128 time=1.39 ms
64 bytes from 192.168.137.1: icmp_seq=10 ttl=128 time=1.29 ms
64 bytes from 192.168.137.1: icmp_seq=11 ttl=128 time=1.26 ms
64 bytes from 192.168.137.1: icmp_seq=12 ttl=128 time=1.14 ms
64 bytes from 192.168.137.1: icmp_seq=13 ttl=128 time=1.22 ms
64 bytes from 192.168.137.1: icmp_seq=14 ttl=128 time=1.37 ms
64 bytes from 192.168.137.1: icmp_seq=15 ttl=128 time=1.14 ms
^C
— 192.168.137.1 ping statistics —
15 packets transmitted, 15 received, 0% packet loss, time 14032ms
rtt min/avg/max/mdev = 1.134/1.411/3.899/0.672 ms
vskumar@ubuntu:~$
==========>
Now, I consider my host2 = 192.168.137.1

Let me ping my VM from Laptop CMD:
==== Pinging Ubuntu IP from CMD prompt =====>
C:\Users\Toshiba>ping 192.168.116.129

Pinging 192.168.116.129 with 32 bytes of data:
Reply from 192.168.116.129: bytes=32 time=2ms TTL=64
Reply from 192.168.116.129: bytes=32 time<1ms TTL=64
Reply from 192.168.116.129: bytes=32 time<1ms TTL=64
Reply from 192.168.116.129: bytes=32 time<1ms TTL=64

Ping statistics for 192.168.116.129:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 2ms, Average = 0ms

C:\Users\Toshiba>
====== Replied VM ====>

It means both hosts are working fine.
Now, below block we should add to our hosts file to connect them:

[servers]
host1 ansible_ssh_host=192.168.116.129
host2 ansible_ssh_host=192.168.137.1
We can consider two groups from these two hosts.
Let me check the files as below:
==== List the current files ====>

vskumar@ubuntu:/etc/ansible$ ls -l
total 28
-rw-r–r– 1 root root 19155 Jan 31 15:21 ansible.cfg
-rw-r–r– 1 root root 1016 Jan 31 15:21 hosts
drwxr-xr-x 2 root root 4096 Jan 31 19:46 roles
vskumar@ubuntu:/etc/ansible$
===============================>

Now, let me update the host file.
=== After adding the content of hosts file ===>
vskumar@ubuntu:/etc/ansible$ sudo vim hosts
[sudo] password for vskumar:
Sorry, try again.
[sudo] password for vskumar:
vskumar@ubuntu:/etc/ansible$
vskumar@ubuntu:/etc/ansible$ tail -10 hosts

# Here’s another example of host ranges, this time there are no
# leading 0s:

## db-[99:101]-node.example.com

[servers]
host1 ansible_ssh_host=192.168.116.129
host2 ansible_ssh_host=192.168.137.1
vskumar@ubuntu:/etc/ansible$
== You can see the lst 3 lines of the hosts file ===>

We also need to add the group name as below in the hosts file.

[group_name]
alias ansible_ssh_host=your_server_ip

Here, the group_name is an organizational tag that you will refer to any servers listed
under it with one word.
The alias is just a name to refer to that server.
Now let me add the above lines in hosts above the servers line as below.
[ansible_test1]
alias ansible_ssh_host=192.168.116.129
===== Hosts updated – latest ===>
vskumar@ubuntu:/etc/ansible$ sudo vim hosts
vskumar@ubuntu:/etc/ansible$
vskumar@ubuntu:/etc/ansible$ tail -10 hosts
# leading 0s:

## db-[99:101]-node.example.com
[ansible_test1]
alias ansible_ssh_host=192.168.116.129

[servers]
host1 ansible_ssh_host=192.168.116.129
host2 ansible_ssh_host=192.168.137.1

vskumar@ubuntu:/etc/ansible$
==============================>

Now let me goto ansible dir:
======>
vskumar@ubuntu:~$ cd /etc/ansible
vskumar@ubuntu:/etc/ansible$
======>

Assuming in our Ansible test scenario,
we are imagining that we have two servers we are going to control with Ansible.
These servers are accessible from the Ansible server by typing:
$ssh root@your_server_ip

Means as:
$ssh root@192.168.116.129

==============>
vskumar@ubuntu:/etc/ansible$ ssh root@192.168.116.129
ssh: connect to host 192.168.116.129 port 22: Connection refused
vskumar@ubuntu:/etc/ansible$
==============>
TROUBLE SHOOT THE HOSTS:
=== Trouble shoot ===>
vskumar@ubuntu:/etc/ansible$ ansible -m ping all
host1 | UNREACHABLE! => {
“changed”: false,
“msg”: “Failed to connect to the host via ssh: ssh: connect to host 192.168.116.129 port 22: Connection refused\r\n”,
“unreachable”: true
}
alias | UNREACHABLE! => {
“changed”: false,
“msg”: “Failed to connect to the host via ssh: ssh: connect to host 192.168.116.129 port 22: Connection refused\r\n”,
“unreachable”: true
}
host2 | UNREACHABLE! => {
“changed”: false,
“msg”: “Failed to connect to the host via ssh: \r\n ****USAGE WARNING****\r\n\r\nThis is a private computer system. This computer system, including all\r\nrelated equipment, networks, and network devices (specifically including\r\nInternet access) are provided only for authorized use. This computer system\r\nmay be monitored for all lawful purposes, including to ensure that its use\r\nis authorized, for management of the system, to facilitate protection against\r\nunauthorized access, and to verify security procedures, survivability, and\r\noperational security. Monitoring includes active attacks by authorized entities\r\nto test or verify the security of this system. During monitoring, information\r\nmay be examined, recorded, copied and used for authorized purposes. All\r\ninformation, including personal information, placed or sent over this system\r\nmay be monitored.\r\n\r\nUse of this computer system, authorized or unauthorized, constitutes consent\r\nto monitoring of this system. Unauthorized use may subject you to criminal\r\nprosecution. Evidence of unauthorized use collected during monitoring may be\r\nused for administrative, criminal, or other adverse action. Use of this system\r\nconstitutes consent to monitoring for these purposes.\r\n\r\n\r\nPermission denied (publickey,password,keyboard-interactive).\r\n”,
“unreachable”: true
}
vskumar@ubuntu:/etc/ansible$
===============>
The reason for the above error is;
With our current settings, we tried to connect to any of these hosts with Ansible,
the command failed.
This is because your SSH key is embedded for the root user on the remote systems
and Ansible will by default try to connect as your current user.
A connection attempt will get the above error.

To rectify it;
We can create a file that tells all of the servers in the “servers” group to connect
using the root user.

To do this, we will create a directory in the Ansible configuration structure called group_vars.
Let us use the below dir commands:
$sudo mkdir /etc/ansible/group_vars

========================>
vskumar@ubuntu:/etc/ansible$ sudo mkdir /etc/ansible/group_vars
vskumar@ubuntu:/etc/ansible$ ls -l
total 32
-rw-r–r– 1 root root 19155 Jan 31 15:21 ansible.cfg
drwxr-xr-x 2 root root 4096 Mar 6 08:52 group_vars
-rw-r–r– 1 root root 1158 Mar 6 08:20 hosts
drwxr-xr-x 2 root root 4096 Jan 31 19:46 roles
vskumar@ubuntu:/etc/ansible$
=================>
Within this folder, we can create YAML-formatted files for each group we want to configure.
By using below command:
$sudo vim /etc/ansible/group_vars/servers
We can put our configuration in here. YAML files start with “—“, so make sure you don’t forget that part.

Below Code:

ansible_ssh_user: root

==========>
udo vim /etc/ansible/group_vars/servers
vskumar@ubuntu:/etc/ansible$ cat /etc/ansible/group_vars/servers


ansible_ssh_user: root
vskumar@ubuntu:/etc/ansible$
=======================>

NOTE:
If you want to specify configuration details for every server, regardless of group association, you can put those details in a file at: 

/etc/ansible/group_vars/all.

Individual hosts can be configured by creating files under a directory at: /etc/ansible/host_vars.

Assuming this helped you to configure your Ansible.

Please leave your positive comment for others also to follow.

You can see next blog on ssh setup and usage from the below url:

https://vskumar.blog/2018/05/26/27-devopsworking-with-ssh-for-ansible-usage/

I have made a video for Ansible installation using Ubuntu 18.04 VM:

16. DevOps: Working with Git on Ubuntu 16.04 VM

Git-logo

In this GIT exercise, I would like to present the below lab sessions for git in an Ubuntu 16.04 VM for the people who attended my sessions so far.
1. How to install git in ubuntu [linux] ?:
2. How To Set Up Git ?:
3. How to check the config file content? :
4. How to clone a project from an url ?:
5. How to Create a test dir or folder for git project?:
6. How initiate the git for the current folder or dir in linux ?:
7. How to Create local files and check the status in the current git folder?:
8. How to commit the files into a local repository and check their status ?:
9. How to commit files into local repo with a message ?:
10. How to check the history of the local git repository ?:
11. How to identify the difference of two commit ids ?:
12. How to check and operate the staged files in local repository ?:
13. What are the ultimate format of the git log ?:
14. How to setup aliases for different git commands?:
15. How to use tags and operate for different versions in a repository?:
16. How to revert back the changes to older version ?:
17. How to cancel the committed changes? :
18. How to reset the reverted changes through commit from the branch? :

19. Working with git directory:

     20. Working with git branches and master :

     21. How to Merge latest objects into single branch ?:

 

1. How to install git in ubuntu [linux] ?:

$sudo apt-get update

$sudo apt-get install git

2. How To Set Up Git ?:
$git config –global user.name “Your Name”

$git config –global user.email “youremail@domain.com”

Ex:
git config –global user.kumar2018 “Vskumar”
git config –global user.email “vskumar35@gmail.com”

==== Screen output for the above commands==>
vskumar@ubuntu:~$ git config –global user.kumar2018 “Vskumar”
vskumar@ubuntu:~$ git config –global user.email “vskumar35@gmail.com”
vskumar@ubuntu:~$ git config –list
user.kumar2018=Vskumar
user.email=vskumar35@gmail.com
vskumar@ubuntu:~$
===========>
3. How to check the config file content? :

$cat ~/.gitconfig
==== Output of config file ===>
vskumar@ubuntu:~$ cat ~/.gitconfig
[user]
kumar2018 = Vskumar
email = vskumar35@gmail.com
vskumar@ubuntu:~$
=============>

4. How to clone a project from an url ?: Let us clone one project as below:
$git clone https://github.com/vskumar2017/VSKTestproject1

=== Screen outout ==>
vskumar@ubuntu:~$
vskumar@ubuntu:~$ sudo git clone https://github.com/vskumar2017/VSKTestproject1
Cloning into ‘VSKTestproject1’…
remote: Counting objects: 57, done.
remote: Total 57 (delta 0), reused 0 (delta 0), pack-reused 57
Unpacking objects: 100% (57/57), done.
Checking connectivity… done.
vskumar@ubuntu:~$
vskumar@ubuntu:~$ ls
data-volume1 examples.desktop Pictures VSKTestproject1
Desktop flask-test Public
Documents jdk-9.0.4_linux-x64_bin.tar.gz Templates
Downloads Music Videos
vskumar@ubuntu:~$
=====================>
5. How to Create a test dir or folder for git project?:

=============>
vskumar@ubuntu:~$ mkdir test-git
vskumar@ubuntu:~$ pwd
/home/vskumar
vskumar@ubuntu:~$ ls
data-volume1 examples.desktop Pictures Videos
Desktop flask-test Public VSKTestproject1
Documents jdk-9.0.4_linux-x64_bin.tar.gz Templates
Downloads Music test-git
vskumar@ubuntu:~$
vskumar@ubuntu:~$
vskumar@ubuntu:~$ cd test-git
vskumar@ubuntu:~/test-git$ ls
vskumar@ubuntu:~/test-git$
=======>
6. How initiate the git for the current folder or dir in linux ?:
== Initialize the current dir for git init===>
vskumar@ubuntu:~/test-git$ git init
Initialized empty Git repository in /home/vskumar/test-git/.git/
vskumar@ubuntu:~/test-git$
========>

7. How to Create local files and check the status in the current git folder?:
== Create a text file========>
vskumar@ubuntu:~/test-git$ echo “Testing line1 for git ..” >> test1.txt vskumar@ubuntu:~/test-git$ cat test1.txt Testing line1 for git .. vskumar@ubuntu:~/test-git$ ls -l
total 4
-rw-rw-r– 1 vskumar vskumar 25 Feb 24 04:03 test1.txt

vskumar@ubuntu:~/test-git$ git status On branch master Initial commit Untracked files: (use “git add <file>…” to include in what will be committed) test1.txt nothing added to commit but untracked files present (use “git add” to track) vskumar@ubuntu:~/test-git$
===== Add a new file====>
vskumar@ubuntu:~/test-git$ git add test1.txt
vskumar@ubuntu:~/test-git$ git status
On branch master
Initial commit

Changes to be committed:
(use “git rm –cached <file>…” to unstage)

new file: test1.txt

vskumar@ubuntu:~/test-git$

===========>

8. How to commit the files into a local repository and check their status ?:

Now, let us do simple commit the file to the local repo.

$git commit -m “First Commit”
=== Commite output ==>
vskumar@ubuntu:~/test-git$ git commit -m “First Commit”
[master (root-commit) 56ccc1e] First Commit
1 file changed, 1 insertion(+)
create mode 100644 test1.txt
vskumar@ubuntu:~/test-git$
======================>
We can check the current status:

=== status after commit ===>
vskumar@ubuntu:~/test-git$ git status
On branch master
nothing to commit, working directory clean
vskumar@ubuntu:~/test-git$
==========>

== Added a new message ===>
vskumar@ubuntu:~/test-git$ echo ‘Testing line2 for git—->’ >> test1.txt
vskumar@ubuntu:~/test-git$ cat test1.txt
Testing line1 for git ..
Testing line2 for git—->
vskumar@ubuntu:~/test-git$
===============>

=== Current status ===>
vskumar@ubuntu:~/test-git$ git status
On branch master
Changes not staged for commit:
(use “git add <file>…” to update what will be committed)
(use “git checkout — <file>…” to discard changes in working directory)

modified: test1.txt

no changes added to commit (use “git add” and/or “git commit -a”)
vskumar@ubuntu:~/test-git$
=====================>
Now, add these two files:
git add test1.txt
git add test2.txt

=== Add and check status for two files ==>
vskumar@ubuntu:~/test-git$ git add test1.txt
vskumar@ubuntu:~/test-git$ git add test2.txt
vskumar@ubuntu:~/test-git$ git status
On branch master
Changes to be committed:
(use “git reset HEAD <file>…” to unstage)

modified: test1.txt
new file: test2.txt

vskumar@ubuntu:~/test-git$
====================================>
9. How to commit files into local repo with a message ?:

Commit these two files:

git commit -m “Committed:Changes for test1.txt and test2.txt”

==== Committed changes and status ===>
vskumar@ubuntu:~/test-git$ git commit -m “Committed:Changes for test1.txt and test2.txt”
[master 2a7192d] Committed:Changes for test1.txt and test2.txt
2 files changed, 2 insertions(+)
create mode 100644 test2.txt
vskumar@ubuntu:~/test-git$ git status
On branch master
nothing to commit, working directory clean
vskumar@ubuntu:~/test-git$
======================================>

Now, let us test the add command . prompt by having 2 or more files.

=== Updated two files ==>
vskumar@ubuntu:~/test-git$ cat test1.txt
Testing line1 for git ..
Testing line2 for git—->
Testing test1.tx for add . function
vskumar@ubuntu:~/test-git$ cat test2.txt
File Test2: Testing for Git commit –>
Testing test2.tx for add . function
vskumar@ubuntu:~/test-git$
=============>
Let us check the status:
==== Status ==>

vskumar@ubuntu:~/test-git$ git status
On branch master
Changes not staged for commit:
(use “git add <file>…” to update what will be committed)
(use “git checkout — <file>…” to discard changes in working directory)

modified: test1.txt
modified: test2.txt

no changes added to commit (use “git add” and/or “git commit -a”)
vskumar@ubuntu:~/test-git$
===============>

Now to add these two file together we need to use ‘git addd .’
== Added all files ===>
vskumar@ubuntu:~/test-git$
vskumar@ubuntu:~/test-git$ git add .
vskumar@ubuntu:~/test-git$ git status
On branch master
Changes to be committed:
(use “git reset HEAD <file>…” to unstage)

modified: test1.txt
modified: test2.txt

vskumar@ubuntu:~/test-git$
============>
Now let us commit the changes of one file at a time.

=== test1.txt commitment===>
vskumar@ubuntu:~/test-git$ git commit test1.txt -m ‘Committed test1.txt 3rd change’
[master 6bfd9b0] Committed test1.txt 3rd change
1 file changed, 1 insertion(+)
vskumar@ubuntu:~/test-git$ ^C
============================>
Now, let us check the status:

=======>
vskumar@ubuntu:~/test-git$
vskumar@ubuntu:~/test-git$ git status
On branch master
Changes to be committed:
(use “git reset HEAD <file>…” to unstage)

modified: test2.txt

vskumar@ubuntu:~/test-git$
========>
In git we can check the history by using ‘git log’ command.

=== Histroy ====>
vskumar@ubuntu:~/test-git$ git log
commit 69282e8d8c07e7cbc68e93b16df1d943d3b518d5
Author: Vsk <vskumar35@gmail.com>
Date: Sat Feb 24 06:49:27 2018 -0800

Committed test2.txt 3rd change

commit 6bfd9b045c352f13c36d8f82f12567058a8bb468
Author: Vsk <vskumar35@gmail.com>
Date: Sat Feb 24 06:46:24 2018 -0800

Committed test1.txt 3rd change

commit 2a7192dcdd1a123b8164f0d48dd0631645cf0630
Author: Vsk <vskumar35@gmail.com>
Date: Sat Feb 24 06:32:03 2018 -0800

Committed:Changes for test1.txt and test2.txt

commit 56ccc1ec9ae7db9f97e3a08e5488a64b4f130f1b
Author: Vsk <vskumar35@gmail.com>
Date: Sat Feb 24 06:08:42 2018 -0800

First Commit
vskumar@ubuntu:~/test-git$
=====================>
10. How to check the history of the local git repository ?:

In git we can check the history by using ‘git log’ command. It can give entire committed history with the relevant comments. If we use ‘git log –pretty=oneline’ it gives only chekcsums for different times commited occasions with commit the messages.

If we use ‘git log –pretty=oneline’ it gives only chekcsums for different times commited occasions with commit the messages.

=== Output for pretty ===>
vskumar@ubuntu:~/test-git$ git log –pretty=oneline
69282e8d8c07e7cbc68e93b16df1d943d3b518d5 Committed test2.txt 3rd change
6bfd9b045c352f13c36d8f82f12567058a8bb468 Committed test1.txt 3rd change
2a7192dcdd1a123b8164f0d48dd0631645cf0630 Committed:Changes for test1.txt and test2.txt
56ccc1ec9ae7db9f97e3a08e5488a64b4f130f1b First Commit
vskumar@ubuntu:~/test-git$
==============>

We can also check the commitments by author also using
‘git log –pretty=oneline –author=<your name>’

git log –pretty=oneline –author=kumar

============>
vskumar@ubuntu:~/test-git$ git log –pretty=oneline –author=kumar
69282e8d8c07e7cbc68e93b16df1d943d3b518d5 Committed test2.txt 3rd change
6bfd9b045c352f13c36d8f82f12567058a8bb468 Committed test1.txt 3rd change
2a7192dcdd1a123b8164f0d48dd0631645cf0630 Committed:Changes for test1.txt and test2.txt
56ccc1ec9ae7db9f97e3a08e5488a64b4f130f1b First Commit
============>
Let me give wrong user name to test:
=== Wrong user name ====>
vskumar@ubuntu:~/test-git$ git log –pretty=oneline –author=kumar1
vskumar@ubuntu:~/test-git$ git log –pretty=oneline –author=kumar202
vskumar@ubuntu:~/test-git$
= No files committed for the above users ==>

We can see more detail about a particular commit through show command.
The command ‘git log’ yields a sequential history of the individual commits within the repository.
Then you need to collect the commit id.

=== git show =====>
vskumar@ubuntu:~/test-git$ git show 56ccc1ec9ae7db9f97e3a08e5488a64b4f130f1b
commit 56ccc1ec9ae7db9f97e3a08e5488a64b4f130f1b
Author: Vsk <vskumar35@gmail.com>
Date: Sat Feb 24 06:08:42 2018 -0800

First Commit

diff –git a/test1.txt b/test1.txt
new file mode 100644
index 0000000..73b0484
— /dev/null
+++ b/test1.txt
@@ -0,0 +1 @@
+Testing line1 for git ..
vskumar@ubuntu:~/test-git$
=============================>
11. How to identify the difference of two commit ids ?:
The diff command recalls both full commit ID names and run ‘git diff’

git diff 2a7192dcdd1a123b8164f0d48dd0631645cf0630 6bfd9b045c352f13c36d8f82f12567058a8bb468

== Output of two commit diffs ==>
vskumar@ubuntu:~/test-git$ git diff 2a7192dcdd1a123b8164f0d48dd0631645cf0630 6bfd9b045c352f13c36d8f82f12567058a8bb468
diff –git a/test1.txt b/test1.txt
index 931bb8b..b9132c1 100644
— a/test1.txt
+++ b/test1.txt
@@ -1,2 +1,3 @@
Testing line1 for git ..
Testing line2 for git—->
+Testing test1.tx for add . function
vskumar@ubuntu:~/test-git$
==============================>
12. How to check and operate the staged files in local repository ?:

We can use the below command:
git ls-files –stage

=== Stage of current files ===>
vskumar@ubuntu:~/test-git$
vskumar@ubuntu:~/test-git$ git ls-files –stage
100644 b9132c1dd4ac08fa9c1e3dea5d7100e33557ad20 0 test1.txt
100644 0866cfd2c7ac9bf17f0a0590551a3580359e7250 0 test2.txt
vskumar@ubuntu:~/test-git$
========================>
=== Rm and later files stage ==>
vskumar@ubuntu:~/test-git$ git rm –cached test1.txt
rm ‘test1.txt’
vskumar@ubuntu:~/test-git$ git ls-files –stage
100644 0866cfd2c7ac9bf17f0a0590551a3580359e7250 0 test2.txt
vskumar@ubuntu:~/test-git$
vskumar@ubuntu:~/test-git$ git rm –cached test1.txt
rm ‘test1.txt’
vskumar@ubuntu:~/test-git$ git ls-files –stage
100644 0866cfd2c7ac9bf17f0a0590551a3580359e7250 0 test2.txt
vskumar@ubuntu:~/test-git$
=====>
You can see the removed file is back into dir:
== Status of removed file ==>
vskumar@ubuntu:~/test-git$ git status
On branch master
Changes to be committed:
(use “git reset HEAD <file>…” to unstage)
deleted: test1.txt
Untracked files:
(use “git add <file>…” to include in what will be committed)

test1.txt
vskumar@ubuntu:~/test-git$
=== It need to be be added and committed ====>
vskumar@ubuntu:~/test-git$ git add .
vskumar@ubuntu:~/test-git$ git status
On branch master
nothing to commit, working directory clean
vskumar@ubuntu:~/test-git$
======= It need to be added only===.

====== list the stage files =>
vskumar@ubuntu:~/test-git$
vskumar@ubuntu:~/test-git$ git ls-files –stage
100644 b9132c1dd4ac08fa9c1e3dea5d7100e33557ad20 0 test1.txt
100644 0866cfd2c7ac9bf17f0a0590551a3580359e7250 0 test2.txt
vskumar@ubuntu:~/test-git$
=========================>
13. What are the ultimate format of the git log ?:
We can use the ultimate format of the log as: git log –pretty=format:”%h %ad | %s%d [%an]” –graph –date=short

===== Screen output ==========>
vskumar@ubuntu:~$ cd test-git vskumar@ubuntu:~/test-git$ pwd /home/vskumar/test-git vskumar@ubuntu:~/test-git$ git log –pretty=format:”%h %ad | %s%d [%an]” –graph –date=short * 69282e8 2018-02-24 | Committed test2.txt 3rd change (HEAD -> master) [Vsk] * 6bfd9b0 2018-02-24 | Committed test1.txt 3rd change [Vsk] * 2a7192d 2018-02-24 | Committed:Changes for test1.txt and test2.txt [Vsk] * 56ccc1e 2018-02-24 | First Commit [Vsk] vskumar@ubuntu:~/test-git$

==============================>

14. How to setup aliases for different git commands?:

If there is a common and complex the Git command you type frequently, consider setting up a simple Git alias for it.

We can use the below common aliases:

git config –global alias.ci commit

git config –global alias.st status

git config –global alias.br branch

git config –global alias.hist “log –pretty=format:’%h %ad | %s%d [%an]’ –graph –date=short”

Once you setup the above aliases for git commands you need to use them only, instead of commands.

Like; for command: ‘log –pretty=format:’%h %ad | %s%d [%an]’ –graph –date=short You need to use git hist, etc.

You also need to remember them well. Once you setup the above aliases for git commands you need to use them only instead of commands.

Like; for command: ‘log –pretty=format:”%h %ad | %s%d [%an]” –graph –date=short’

You need to use git hist, etc. You also need to remember them well.

Let us try one command for branch:

===== Screen output ==========>

vskumar@ubuntu:~$ cd test-git

vskumar@ubuntu:~/test-git$ pwd /home/vskumar/test-git

vskumar@ubuntu:~/test-git$ git log –pretty=format:”%h %ad | %s%d [%an]” –graph –date=short

* 69282e8 2018-02-24 | Committed test2.txt 3rd change (HEAD -> master) [Vsk]

*6bfd9b0 2018-02-24 | Committed test1.txt 3rd change [Vsk]

* 2a7192d 2018-02-24 | Committed:Changes for test1.txt and test2.txt [Vsk]

* 56ccc1e 2018-02-24 | First Commit [Vsk] vskumar@ubuntu:~/test-git$ ==========================>

=== History =======>

vskumar@ubuntu:~/test-git$ git log –pretty=format:”%h %ad | %s%d [%an]” –graph –date=short

* 69282e8 2018-02-24 | Committed test2.txt 3rd change (HEAD -> master) [Vsk]

* 6bfd9b0 2018-02-24 | Committed test1.txt 3rd change [Vsk]

* 2a7192d 2018-02-24 | Committed:Changes for test1.txt and test2.txt [Vsk]

* 56ccc1e 2018-02-24 | First Commit [Vsk]

vskumar@ubuntu:~/test-git$ git config –global alias.hist “log –pretty=format:’%h %ad | %s%d [%an]’ –grap h –date=short”

==== With alias hist ========>

vskumar@ubuntu:~/test-git$ git hist

* 69282e8 2018-02-24 | Committed test2.txt 3rd change (HEAD -> master) [Vsk]

* 6bfd9b0 2018-02-24 | Committed test1.txt 3rd change [Vsk]

* 2a7192d 2018-02-24 | Committed:Changes for test1.txt and test2.txt [Vsk]

* 56ccc1e 2018-02-24 | First Commit [Vsk]

vskumar@ubuntu:~/test-git$

==========================>

15. How to use tags and operate for different versions in a repository?:

Tags for previous versions of git: W

We can tag latest committed versions from a local repo to reuse them later stages. Let’s tag the version prior to the current version with the name v1.

First, we will checkout the previous version. Instead of looking up the hash, we are going to use the  notation indicating “the parent of v1”. git tag v1

=== You can see the tagging process for the latest commit ===>

vskumar@ubuntu:~/test-git$

vskumar@ubuntu:~/test-git$ git hist

* 69282e8 2018-02-24 | Committed test2.txt 3rd change (HEAD -> master) [Vsk]

* 6bfd9b0 2018-02-24 | Committed test1.txt 3rd change [Vsk]

* 2a7192d 2018-02-24 | Committed:Changes for test1.txt and test2.txt [Vsk]

* 56ccc1e 2018-02-24 | First Commit [Vsk]

vskumar@ubuntu:~/test-git$ git tag v1

vskumar@ubuntu:~/test-git$ git checkout v1

Note: checking out ‘v1’. You are in ‘detached HEAD’ state. You can look around, make experimental changes and commit them, and you can discard any commits you make in this state without impacting any branches by performing another checkout. If you want to create a new branch to retain commits you create, you may do so (now or later) by using -b with the checkout command again. Example: git checkout -b <new-branch-name> HEAD is now at 69282e8… Committed test2.txt 3rd change

vskumar@ubuntu:~/test-git$ git hist

* 69282e8 2018-02-24 | Committed test2.txt 3rd change (HEAD, tag: v1, master) [Vsk]

* 6bfd9b0 2018-02-24 | Committed test1.txt 3rd change [Vsk]

* 2a7192d 2018-02-24 | Committed:Changes for test1.txt and test2.txt [Vsk]

* 56ccc1e 2018-02-24 | First Commit [Vsk]

vskumar@ubuntu:~/test-git$ git status

HEAD detached at v1 nothing to commit, working directory clean vskumar@ubuntu:~/test-git$

================================>

Now, let us add a line to test1.txt and commit it.

===== Screen output ===>

vskumar@ubuntu:~/test-git$ ls -l total 8

-rw-rw-r– 1 vskumar vskumar 88 Feb 24 06:37 test1.txt

-rw-rw-r– 1 vskumar vskumar 75 Feb 24 06:37 test2.txt

vskumar@ubuntu:~/test-git$ git status

HEAD detached at v1 nothing to commit, working directory clean vskumar@ubuntu:~/test-git$

vskumar@ubuntu:~/test-git$ echo ‘Testing test1.txt for tagging v2’ >> test1.txt vskumar@ubuntu:~/test-git$ cat test1.txt

Testing line1 for git .. Testing line2 for git—->

Testing test1.tx for add . function

Testing test1.txt for tagging v2

vskumar@ubuntu:~/test-git$ git status

HEAD detached at v1 Changes not staged for commit: (use “git add <file>…” to update what will be committed) (use “git checkout — <file>…” to discard changes in working directory) modified: test1.txt no changes added to commit (use “git add” and/or “git commit -a”)

vskumar@ubuntu:~/test-git$

========================>

Now let me add and commit

=== Add and commit for tagging 2nd time ===>

vskumar@ubuntu:~/test-git$ git add .

vskumar@ubuntu:~/test-git$ git status

HEAD detached at v1 Changes to be committed: (use “git reset HEAD <file>…” to unstage) modified: test1.txt

vskumar@ubuntu:~/test-git$ git commit -m ‘Added for tagging 2nd time’

[detached HEAD 0bec7c0] Added for tagging 2nd time 1 file changed, 1 insertion(+) vskumar@ubuntu:~/test-git$ git status HEAD detached from v1 nothing to commit, working directory clean

vskumar@ubuntu:~/test-git$

===============>

Now, let us tag 2nd time :

== You can see two versions are tagged ===>

vskumar@ubuntu:~/test-git$

vskumar@ubuntu:~/test-git$ git hist

* 0bec7c0 2018-02-24 | Added for tagging 2nd time (HEAD) [Vsk]

* 69282e8 2018-02-24 | Committed test2.txt 3rd change (tag: v1, master) [Vsk]

* 6bfd9b0 2018-02-24 | Committed test1.txt 3rd change [Vsk]

* 2a7192d 2018-02-24 | Committed:Changes for test1.txt and test2.txt [Vsk]

* 56ccc1e 2018-02-24 | First Commit [Vsk]

vskumar@ubuntu:~/test-git$ git tag v2

vskumar@ubuntu:~/test-git$ git hist

* 0bec7c0 2018-02-24 | Added for tagging 2nd time (HEAD, tag: v2) [Vsk]

* 69282e8 2018-02-24 | Committed test2.txt 3rd change (tag: v1, master) [Vsk]

* 6bfd9b0 2018-02-24 | Committed test1.txt 3rd change [Vsk]

* 2a7192d 2018-02-24 | Committed:Changes for test1.txt and test2.txt [Vsk]

* 56ccc1e 2018-02-24 | First Commit [Vsk]

vskumar@ubuntu:~/test-git$

===========================>

Now let us check the latest version of test1.txt content.

=== Latest version test1.txt ===>

vskumar@ubuntu:~/test-git$ ls -l

total 8 -rw-rw-r– 1

vskumar vskumar 121 Feb 24 20:58 test1.txt -rw-rw-r– 1 vskumar vskumar 75 Feb 24 06:37 test2.txt

vskumar@ubuntu:~/test-git$ cat test1.txt

Testing line1 for git .. Testing line2 for git—-> Testing test1.tx for add . function Testing test1.txt for tagging v2

vskumar@ubuntu:~/test-git$

============>

Now, let us checkout the older version to test the content of test1.txt. using : git checkout v1

====== Chekout v1 to track changes ====>

vskumar@ubuntu:~/test-git$ git checkout v1

Previous HEAD position was 0bec7c0… Added for tagging 2nd time HEAD is now at 69282e8… Committed test2.txt 3rd change

vskumar@ubuntu:~/test-git$ cat test1.txt

Testing line1 for git .. Testing line2 for git—->

Testing test1.tx for add . function

vskumar@ubuntu:~/test-git$

vskumar@ubuntu:~/test-git$ git status

HEAD detached at v1 nothing to commit, working directory clean

vskumar@ubuntu:~/test-git$

=== We can see the older version content only===>

===== We can see the hist and make the current master checkout s v1 ===> vskumar@ubuntu:~/test-git$ git hist

* 69282e8 2018-02-24 | Committed test2.txt 3rd change (HEAD, tag: v1, master) [Vsk]

* 6bfd9b0 2018-02-24 | Committed test1.txt 3rd change [Vsk]

* 2a7192d 2018-02-24 | Committed:Changes for test1.txt and test2.txt [Vsk]

* 56ccc1e 2018-02-24 | First Commit [Vsk]

vskumar@ubuntu:~/test-git$

vskumar@ubuntu:~/test-git$ git checkout

master Switched to branch ‘master’

vskumar@ubuntu:~/test-git$ git hist

* 69282e8 2018-02-24 | Committed test2.txt 3rd change (HEAD -> master, tag: v1) [Vsk]

* 6bfd9b0 2018-02-24 | Committed test1.txt 3rd change [Vsk]

* 2a7192d 2018-02-24 | Committed:Changes for test1.txt and test2.txt [Vsk]

* 56ccc1e 2018-02-24 | First Commit [Vsk] vskumar@ubuntu:~/test-git$ vskumar@ubuntu:~/test-git$ git status On branch master nothing to commit, working directory clean

vskumar@ubuntu:~/test-git$

==============================>

16. How to revert back the changes to older version ?:

Now, let us understand on how to revertback the changes in a local file.

We can use reset command to bring back the previous version. If you have a modified object in the working dir and want to revertback to older version you can follow the below steps.

The reset command resets the buffer zone to HEAD. This clears the buffer zone from the changes that we have just staged. The reset command (default) does not change the working directory. Hence, the working directory still contains unwanted comments.

We can use the checkout command from the previous tutorial to remove unwanted changes from working directory.

===== to revertback Reset the modified file and checkout that file only =====> vskumar@ubuntu:~/test-git$ git status On branch master nothing to commit, working directory clean

vskumar@ubuntu:~/test-git$ echo ‘Testing for reset Head command’ >> test1.txt vskumar@ubuntu:~/test-git$ git status On branch master Changes not staged for commit: (use “git add <file>…” to update what will be committed) (use “git checkout — <file>…” to discard changes in working directory) modified: test1.txt no changes added to commit (use “git add” and/or “git commit -a”)

vskumar@ubuntu:~/test-git$ git reset HEAD test1.txt Unstaged changes after reset: M test1.txt

vskumar@ubuntu:~/test-git$ git status On branch master Changes not staged for commit: (use “git add <file>…” to update what will be committed) (use “git checkout — <file>…” to discard changes in working directory) modified: test1.txt no changes added to commit (use “git add” and/or “git commit -a”)

vskumar@ubuntu:~/test-git$

=== Finally, You can see the older version contents only ====>

17. How to cancel the committed changes? :

We have seen on how to cancel the modified files.

Now we can check on how to revert back the committed changes in the local git repo.

== Let us see the current hist ===>

vskumar@ubuntu:~/test-git$ git hist

* 69282e8 2018-02-24 | Committed test2.txt 3rd change (HEAD -> master, tag: v1) [Vsk]

* 6bfd9b0 2018-02-24 | Committed test1.txt 3rd change [Vsk]

* 2a7192d 2018-02-24 | Committed:Changes for test1.txt and test2.txt [Vsk]

* 56ccc1e 2018-02-24 | First Commit [Vsk]

vskumar@ubuntu:~/test-git$

=================>

Now let us consider v1 to revert back.

We need to use command:git revert HEAD. When we use this command it will open a editor by showing the details.

We can save it using ‘wq!’ like in vi/vim.

===== Output =======>

vskumar@ubuntu:~/test-git$ git revert HEAD

[master fdc40ac] Revert “Committed test2.txt 3rd change” 1 file changed, 1 deletion(-)

vskumar@ubuntu:~/test-git$

===================>

Now, let us check hist

=== git hist ====>

vskumar@ubuntu:~/test-git$ git hist

* fdc40ac 2018-02-24 | Revert “Committed test2.txt 3rd change” (HEAD -> master) [Vsk]

* 69282e8 2018-02-24 | Committed test2.txt 3rd change (tag: v1) [Vsk]

* 6bfd9b0 2018-02-24 | Committed test1.txt 3rd change [Vsk]

* 2a7192d 2018-02-24 | Committed:Changes for test1.txt and test2.txt [Vsk]

* 56ccc1e 2018-02-24 | First Commit [Vsk]

vskumar@ubuntu:~/test-git$

=================>

============ Exercise ====================>

If you want to can do an Exercise: You can checkout the committed version. You can add a test to text1 file and commit it. Again you can use the same lab practice.

============ You can revert back also =====>

18. How to reset the reverted changes through commit from the branch? :

Check the previous screen display for the usage of revert command.

Now, if we have decided to reset the changes we can use the command: ‘git reset –hard v1’

=== Screen output for resetting reverted commit=====>

vskumar@ubuntu:~/test-git$ git reset –hard v1

HEAD is now at 69282e8 Committed test2.txt 3rd change

vskumar@ubuntu:~/test-git$ git hist

* 69282e8 2018-02-24 | Committed test2.txt 3rd change (HEAD, tag: v1) [Vsk]

* 6bfd9b0 2018-02-24 | Committed test1.txt 3rd change [Vsk]

* 2a7192d 2018-02-24 | Committed:Changes for test1.txt and test2.txt [Vsk]

* 56ccc1e 2018-02-24 | First Commit [Vsk]

vskumar@ubuntu:~/test-git$

=====================>

We can check the committed history using the below command: git hist –all

==== Screen output git hist –all ===>

vskumar@ubuntu:~/test-git$ git hist –all

* fdc40ac 2018-02-24 | Revert “Committed test2.txt 3rd change” (master) [Vsk] |

* 0bec7c0 2018-02-24 | Added for tagging 2nd time (tag: v2) [Vsk] |

* 69282e8 2018-02-24 | Committed test2.txt 3rd change (HEAD, tag: v1) [Vsk]

* 6bfd9b0 2018-02-24 | Committed test1.txt 3rd change [Vsk]

* 2a7192d 2018-02-24 | Committed:Changes for test1.txt and test2.txt [Vsk]

* 56ccc1e 2018-02-24 | First Commit [Vsk]

vskumar@ubuntu:~/test-git$

=====================>

You can also observe the reverted information.

We can also drop the tags as below: git tag -d v1

===== Output for tag removal ====>

vskumar@ubuntu:~/test-git$ git tag -d v2

Deleted tag ‘v2’ (was 0bec7c0)

vskumar@ubuntu:~/test-git$ git hist –all

* fdc40ac 2018-02-24 | Revert “Committed test2.txt 3rd change” (master) [Vsk]

* 69282e8 2018-02-24 | Committed test2.txt 3rd change (HEAD, tag: v1) [Vsk]

* 6bfd9b0 2018-02-24 | Committed test1.txt 3rd change [Vsk]

* 2a7192d 2018-02-24 | Committed:Changes for test1.txt and test2.txt [Vsk]

* 56ccc1e 2018-02-24 | First Commit [Vsk]

vskumar@ubuntu:~/test-git$

==========So, now v2 tag is removed ========>

You can also see the config file as below:

=== Config file ====>

vskumar@ubuntu:~/test-git$ cat .git/config

[core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true vskumar@ubuntu:~/test-git$

=====This configuration file is created for each individual project.===============>

19. Working with git directory:

 

Every Git project will have directories and files.

We can see the git dir items:

==================== Git dir items ===>

vskumar@ubuntu:~/test-git$ ls -l -C .git

branches        config       HEAD   index  logs     ORIG_HEAD

COMMIT_EDITMSG  description  hooks  info   objects  refs

vskumar@ubuntu:~/test-git$

======Root folder of git project =====>

 

We can explore the objects dir to check the objects details.

using ls -l -C .git/objects

 

==== Output ====>

vskumar@ubuntu:~/test-git$ ls -l -C .git/objects

07  0b  44  4f  68  6b  92  b0  bd  fd    pack

08  2a  47  56  69  73  93  b9  e0  info

vskumar@ubuntu:~/test-git$

================>

 

We can see a lot of folders named with two characters.

The first two letters sha1 hash of the object stored in git are the directory names.

 

What is SHA1 ?:

The SHA-1 (Secure Hash Algorithm 1) is a cryptographic hash function.  

It takes an input and produces a 160-bit (20-byte) hash value known as a message digest to the object.

Typically it is rendered as a hexadecimal number, with 40 digits long.

 

Now, let us see it by inquiring our database objects from the above listed items:

Using the below command we can check the files in dir.

ls -C .git/objects/<dir>   — The dir is the two characters of the above shown values.

==== Checking one dir ====>

vskumar@ubuntu:~/test-git$ ls -l  -C .git/objects/07

5e722b3161a24fd5adcefb574b5360118abbef

vskumar@ubuntu:~/test-git$ ls -l  -C .git/objects/92

d62ee30d26c444d85b3d81a4e2b8b69e0f093f

vskumar@ubuntu:~/test-git$

==== You can see 40 digits size hexadecimal value of objects in 07 and 92 objects dir====>

 

Note, we have seen the config file from the previous exercises.

Now, We will check the branches and tags as below commands:

 

ls .git/refs

ls .git/refs/heads

ls .git/refs/tags

cat .git/refs/tags/v1

 

== Checking branches and tags ===>

vskumar@ubuntu:~/test-git$

vskumar@ubuntu:~/test-git$ ls .git/refs

heads  tags

vskumar@ubuntu:~/test-git$ ls .git/refs/heads

master

vskumar@ubuntu:~/test-git$ ls .git/refs/tags

v1

vskumar@ubuntu:~/test-git$ cat .git/refs/tags/v1

69282e8d8c07e7cbc68e93b16df1d943d3b518d5

vskumar@ubuntu:~/test-git$

=================================>

 

Let us note;  each file corresponds to the tag previously created using the git tag command.

Its content is a hash commit attached to the tag.

We have only one branch, and everything we see here in this folder is a master branch.

Now, let us check what the HEAD file contains?:

using :cat .git/HEAD

 

==============>

vskumar@ubuntu:~/test-git$ cat .git/HEAD

683ed74fda585e10f38111ebb4c84026d5678290

vskumar@ubuntu:~/test-git$

=============>

 

Let us search for the last committed items:

We can explore the structure of the database objects

using SHA1 hashes for searching the content in the repository.

 

The below command should find the last commit in the repository.

======= SHA hash of git hist ==>

vskumar@ubuntu:~/test-git$ git hist –max-count=1

* 683ed74 2018-02-24 | Added updated test1.txt (HEAD) [Vsk]

vskumar@ubuntu:~/test-git$

==============================>

SHA1 hash is probably different on our systems from this git format.

Now, let us check the last commit details.

Using the below commands:

git cat-file -t <hash>

git cat-file -p <hash>

 

==== SHA1 content and the tree details ===>

vskumar@ubuntu:~/test-git$ git cat-file -t 683ed74

commit

vskumar@ubuntu:~/test-git$ git cat-file -p 683ed74

tree 44298909c5e8873c5870f9f1ca77951ea4e028eb

parent 69282e8d8c07e7cbc68e93b16df1d943d3b518d5

author Vsk <vskumar35@gmail.com> 1519544092 -0800

committer Vsk <vskumar35@gmail.com> 1519544092 -0800

Added updated test1.txt

vskumar@ubuntu:~/test-git$

==========================================>

Now, we can display the tree referenced in the above commit.

Using :git cat-file -p <treehash>

From the couple of characters shown for tree.

====== We can see the real files stored under git blob ====>

vskumar@ubuntu:~/test-git$ git cat-file -p 44298909

100644 blob 075e722b3161a24fd5adcefb574b5360118abbef test1.txt

100644 blob 0866cfd2c7ac9bf17f0a0590551a3580359e7250 test2.txt

vskumar@ubuntu:~/test-git$

================================================>

 

== See the contents for text1.txt also ===>

vskumar@ubuntu:~/test-git$ git cat-file -p 075e722b

Testing line1 for git ..

Testing line2 for git—->

Testing test1.tx for add . function

Checking for changing commit comment

vskumar@ubuntu:~/test-git$

====================================>

 

So we have seen the main branch to till the object content level.

 

20. Working with git branches and master :

 

Now, let us see the branches operation. We can create different branches as each developer

can have his/her own branch while working with the same or different objects.

Let us see the current statusof git project:

=========>

vskumar@ubuntu:~/test-git$ pwd

/home/vskumar/test-git

vskumar@ubuntu:~/test-git$ git status

HEAD detached from v1

Changes not staged for commit:

  (use “git add <file>…” to update what will be committed)

  (use “git checkout — <file>…” to discard changes in working directory)

 

modified:   test1.txt

modified:   test2.txt

 

Untracked files:

  (use “git add <file>…” to include in what will be committed)

 

class

test1.class

test1.java

 

no changes added to commit (use “git add” and/or “git commit -a”)

vskumar@ubuntu:~/test-git$

======================>

 

Now, Let us create a new branch as below [using checkout] and test the operations.

 

git checkout -b testgitbr1

git status

 

====== We are just copied the same project as a branch ======>

vskumar@ubuntu:~/test-git$ git checkout -b testgitbr1

M test1.txt

M test2.txt

Switched to a new branch ‘testgitbr1’

vskumar@ubuntu:~/test-git$ git status

On branch testgitbr1

Changes not staged for commit:

  (use “git add <file>…” to update what will be committed)

  (use “git checkout — <file>…” to discard changes in working directory)

 

modified:   test1.txt

modified:   test2.txt

 

Untracked files:

  (use “git add <file>…” to include in what will be committed)

 

class

test1.class

test1.java

 

no changes added to commit (use “git add” and/or “git commit -a”)

vskumar@ubuntu:~/test-git$

==================>

Assume a developer want to add his own program.

Now, I would like to add the test1.java program into this new branch:

======= Adding new file ====>

vskumar@ubuntu:~/test-git$ git add test1.java

vskumar@ubuntu:~/test-git$ git status

On branch testgitbr1

Changes to be committed:

  (use “git reset HEAD <file>…” to unstage)

 

new file:   test1.java

 

Changes not staged for commit:

  (use “git add <file>…” to update what will be committed)

  (use “git checkout — <file>…” to discard changes in working directory)

 

modified:   test1.txt

modified:   test2.txt

 

Untracked files:

  (use “git add <file>…” to include in what will be committed)

 

class

test1.class

 

vskumar@ubuntu:~/test-git$

=== New branch has a java program also ===>

Now, let me commit this file with a message:

 

git commit -m “Added a java program [test1.java] to new branch”

 

========>

vskumar@ubuntu:~/test-git$ git commit -m “Added a java program [test1.java] to new branch”

[testgitbr1 4e7baf8] Added a java program [test1.java] to new branch

 1 file changed, 11 insertions(+)

 create mode 100644 test1.java

vskumar@ubuntu:~/test-git$

=============>

Let us see the status:

 

=== Current status ====>

vskumar@ubuntu:~/test-git$ git status

On branch testgitbr1

Changes not staged for commit:

  (use “git add <file>…” to update what will be committed)

  (use “git checkout — <file>…” to discard changes in working directory)

 

modified:   test1.txt

modified:   test2.txt

 

Untracked files:

  (use “git add <file>…” to include in what will be committed)

 

class

test1.class

 

no changes added to commit (use “git add” and/or “git commit -a”)

vskumar@ubuntu:~/test-git$

========================>

Now let me add all the modified files also with a commit:

 

=======>

vskumar@ubuntu:~/test-git$ git add .

vskumar@ubuntu:~/test-git$ git status

On branch testgitbr1

Changes to be committed:

  (use “git reset HEAD <file>…” to unstage)

 

new file:   class

new file:   test1.class

modified:   test1.txt

modified:   test2.txt

 

vskumar@ubuntu:~/test-git$

vskumar@ubuntu:~/test-git$

vskumar@ubuntu:~/test-git$ git commit -m “Added all 4 files [2-new and 2 modified]”

 

[testgitbr1 26b971b] Added all 4 files [2-new and 2 modified]

 4 files changed, 14 insertions(+), 4 deletions(-)

 create mode 100644 class

 create mode 100644 test1.class

 mode change 100644 => 100755 test1.txt

 mode change 100644 => 100755 test2.txt

vskumar@ubuntu:~/test-git$

vskumar@ubuntu:~/test-git$ git status

On branch testgitbr1

nothing to commit, working directory clean

vskumar@ubuntu:~/test-git$

== So, we have updated the new branch ====>

 

Now we need to navigate the available branches.

Let us apply git hist command and check the history as below:

== Checking the git project repo history ====>

vskumar@ubuntu:~/test-git$ git hist

* 26b971b 2018-03-05 | Added all 4 files [2-new and 2 modified] (HEAD -> testgitbr1) [Vsk]

* 4e7baf8 2018-03-05 | Added a java program [test1.java] to new branch [Vsk]

* 683ed74 2018-02-24 | Added updated test1.txt [Vsk]

* 69282e8 2018-02-24 | Committed test2.txt 3rd change (tag: v1) [Vsk]

* 6bfd9b0 2018-02-24 | Committed test1.txt 3rd change [Vsk]

* 2a7192d 2018-02-24 | Committed:Changes for test1.txt and test2.txt [Vsk]

* 56ccc1e 2018-02-24 | First Commit [Vsk]

vskumar@ubuntu:~/test-git$

== You can see the latest branch and commit messages===>

Now, let us toggle or do workaround between the branch and the master as below:

Please note so far we are with the testgitbr1 which is  branch.

Now let us use master as below:

git checkout master

==== Master ====>

vskumar@ubuntu:~/test-git$ git checkout master

Switched to branch ‘master’

vskumar@ubuntu:~/test-git$ git status

On branch master

nothing to commit, working directory clean

vskumar@ubuntu:~/test-git$

================>

 

Let us check some files and their content:

=== Checking master ===>

 vskumar@ubuntu:~/test-git$ cat test1.txt

Testing line1 for git ..

Testing line2 for git—->

Testing test1.tx for add . function

vskumar@ubuntu:~/test-git$ cat test1.java

cat: test1.java: No such file or directory

vskumar@ubuntu:~/test-git$

==========>

 

Now, let us switch to branch and check the files:

== You can see the difference from master ====>

vskumar@ubuntu:~/test-git$ git checkout testgitbr1

Switched to branch ‘testgitbr1’

vskumar@ubuntu:~/test-git$ git status

On branch testgitbr1

nothing to commit, working directory clean

vskumar@ubuntu:~/test-git$ cat test1.java

 

class test1{

  public static void main(String args[]){

    System.out.println(“Hello Welcome to DevOps course”);

System.out.println(“Hope you are practicing well Jenkins 2.9”);

System.out.println(“Now, create a java object file through javac compiler”);

System.out.println(“Using Jenkins job creation”);

System.out.println(“Once it is created, you run it by java runtime”);

System.out.println(“Now, compare the console output with your expectation!!”);

  }

}

vskumar@ubuntu:~/test-git$ cat test1.txt

echo ‘Testing line1 for git ..’

echo ‘Testing line2 for git—->’

echo ‘Testing test1.tx for add . function’

echo ‘Checking for changing commit comment’

echo ‘For removal of old comment’

vskumar@ubuntu:~/test-git$

==Note the test1.txt has different content from master =====>

 

Now, let us try to add one README file into master.

I want to create the README file as below:

 

== README file content ===>

vskumar@ubuntu:~/test-git$ pwd

/home/vskumar/test-git

vskumar@ubuntu:~/test-git$ git checkout master

Switched to branch ‘master’

vskumar@ubuntu:~/test-git$ git status

On branch master

nothing to commit, working directory clean

vskumar@ubuntu:~/test-git$

vskumar@ubuntu:~/test-git$ touch README

vskumar@ubuntu:~/test-git$ echo “Testing Master and branches” >> README

vskumar@ubuntu:~/test-git$ cat README

Testing Master and branches

vskumar@ubuntu:~/test-git$ echo “Added this README file into master only” >> README

vskumar@ubuntu:~/test-git$ cat README

Testing Master and branches

Added this README file into master only

vskumar@ubuntu:~/test-git$

===================================>

Let us commit this file into master.

 

=== Status ====>

 

vskumar@ubuntu:~/test-git$ git status

On branch master

Untracked files:

  (use “git add <file>…” to include in what will be committed)

 

README

 

nothing added to commit but untracked files present (use “git add” to track)

vskumar@ubuntu:~/test-git$

=======>

 

Add and  Commit it with message :

 

==== Commit master ===>

 

vskumar@ubuntu:~/test-git$ git add README

vskumar@ubuntu:~/test-git$ git status

On branch master

Changes to be committed:

  (use “git reset HEAD <file>…” to unstage)

 

new file:   README

 

vskumar@ubuntu:~/test-git$

===== Added README ====>

Now, Commit:

 

==== Commit master ===>

vskumar@ubuntu:~/test-git$ git commit -m “Added README file into mater”

[master 1fad32b] Added README file into mater

 1 file changed, 2 insertions(+)

 create mode 100644 README

vskumar@ubuntu:~/test-git$

======================>

Now, let us view the current hist of master and branch as below with git hist –all:

 

== Current history ===>

 vskumar@ubuntu:~/test-git$ git hist –all

* 1fad32b 2018-03-05 | Added README file into mater (HEAD -> master) [Vsk]

* fdc40ac 2018-02-24 | Revert “Committed test2.txt 3rd change” [Vsk]

| * 26b971b 2018-03-05 | Added all 4 files [2-new and 2 modified] (testgitbr1) [Vsk]

| * 4e7baf8 2018-03-05 | Added a java program [test1.java] to new branch [Vsk]

| * 683ed74 2018-02-24 | Added updated test1.txt [Vsk]

|/  

* 69282e8 2018-02-24 | Committed test2.txt 3rd change (tag: v1) [Vsk]

* 6bfd9b0 2018-02-24 | Committed test1.txt 3rd change [Vsk]

* 2a7192d 2018-02-24 | Committed:Changes for test1.txt and test2.txt [Vsk]

* 56ccc1e 2018-02-24 | First Commit [Vsk]

vskumar@ubuntu:~/test-git$

=== You can see on top last two commits of both master and branch =========>

 

21. How to Merge latest objects into single branch ?:

 

Now, we have two different branches. We can consolidate both branches versions and

merge them into a new branch for future developers to use them as one latest project.

Let us go back to the testgitbr1 branch and merge it with master by using the below commands.

git checkout testgitbr1

git merge master

================>

vskumar@ubuntu:~/test-git$ git checkout testgitbr1

Switched to branch ‘testgitbr1’

======>

When you use merge command a file opens in vi, just save it as it is.

==========================>

vskumar@ubuntu:~/test-git$ git merge master

Auto-merging test2.txt

Merge made by the ‘recursive’ strategy.

 README    | 2 ++

 test2.txt | 1 –

 2 files changed, 2 insertions(+), 1 deletion(-)

 create mode 100644 README

vskumar@ubuntu:~/test-git$

=================>

And let us see the current history:

git hist –all

 

===== History =====>

vskumar@ubuntu:~/test-git$ git hist –all

*   6b67f05 2018-03-05 | Merge branch ‘master’ into testgitbr1 (HEAD -> testgitbr1) [Vsk]

|\  

| * 1fad32b 2018-03-05 | Added README file into mater (master) [Vsk]

| * fdc40ac 2018-02-24 | Revert “Committed test2.txt 3rd change” [Vsk]

* | 26b971b 2018-03-05 | Added all 4 files [2-new and 2 modified] [Vsk]

* | 4e7baf8 2018-03-05 | Added a java program [test1.java] to new branch [Vsk]

* | 683ed74 2018-02-24 | Added updated test1.txt [Vsk]

|/  

* 69282e8 2018-02-24 | Committed test2.txt 3rd change (tag: v1) [Vsk]

* 6bfd9b0 2018-02-24 | Committed test1.txt 3rd change [Vsk]

* 2a7192d 2018-02-24 | Committed:Changes for test1.txt and test2.txt [Vsk]

* 56ccc1e 2018-02-24 | First Commit [Vsk]

vskumar@ubuntu:~/test-git$

== Let us check the above commit history also =============>

 

From the above exercise, we can conclude any developer can merge his/her current branch into master once they decide to release the code.

 

22. How to reset the earlier created branch from the local repository?:

 

We will see from this exercise, how a developer can reset the earlier branch.

We need to be on the branch now.

we should use ‘git checkout testgitbr1’

 

= Switching to testgitbr1 branch ==>

vskumar@ubuntu:~/test-git$ git checkout testgitbr1

Switched to branch ‘testgitbr1’

vskumar@ubuntu:~/test-git$

============>

Now. let us see the current history of the git local repo:

 

==== Git hist====>

 

vskumar@ubuntu:~/test-git$ git hist

*   6b67f05 2018-03-05 | Merge branch ‘master’ into testgitbr1 (HEAD -> testgitbr1) [Vsk]

|\  

| * 1fad32b 2018-03-05 | Added README file into mater (master) [Vsk]

| * fdc40ac 2018-02-24 | Revert “Committed test2.txt 3rd change” [Vsk]

* | 26b971b 2018-03-05 | Added all 4 files [2-new and 2 modified] [Vsk]

* | 4e7baf8 2018-03-05 | Added a java program [test1.java] to new branch [Vsk]

* | 683ed74 2018-02-24 | Added updated test1.txt [Vsk]

|/  

* 69282e8 2018-02-24 | Committed test2.txt 3rd change (tag: v1) [Vsk]

* 6bfd9b0 2018-02-24 | Committed test1.txt 3rd change [Vsk]

* 2a7192d 2018-02-24 | Committed:Changes for test1.txt and test2.txt [Vsk]

* 56ccc1e 2018-02-24 | First Commit [Vsk]

vskumar@ubuntu:~/test-git$

== Note, both branches info is available ===>

To remove the testgitbr1 branch we need to reset it.

git reset –hard <hash> —> Here the testgitbr1 branch 1st commit Hash is 4e7baf8.

So our command is; git reset –hard 4e7baf8

 

=== Resetting branch ===>

vskumar@ubuntu:~/test-git$ git reset –hard 4e7baf8

HEAD is now at 4e7baf8 Added a java program [test1.java] to new branch

==== Rsetting is done for branch ===>

Now let us check the hist all:

 

===== Hist all =====>

vskumar@ubuntu:~/test-git$ git hist –all

* 1fad32b 2018-03-05 | Added README file into mater (master) [Vsk]

* fdc40ac 2018-02-24 | Revert “Committed test2.txt 3rd change” [Vsk]

| * 4e7baf8 2018-03-05 | Added a java program [test1.java] to new branch (HEAD -> testgitbr1) [Vsk]

| * 683ed74 2018-02-24 | Added updated test1.txt [Vsk]

|/  

* 69282e8 2018-02-24 | Committed test2.txt 3rd change (tag: v1) [Vsk]

* 6bfd9b0 2018-02-24 | Committed test1.txt 3rd change [Vsk]

* 2a7192d 2018-02-24 | Committed:Changes for test1.txt and test2.txt [Vsk]

* 56ccc1e 2018-02-24 | First Commit [Vsk]

vskumar@ubuntu:~/test-git$

== Note;testgitbr1 branch is disappeared ====>

Now let us see the latest history.

So, this way any developer can create and merge a branch and later on it can be destroyed also.

 

23. How to add the current code to github?:

 

create a new repository or use the existing repo on the command line

Create your own github userid and a project in it.

Then you can create repository online. You will see set of commands display on the web page.

Follow them. Or follow as below:

 

Steps for Guthub access:

 

You need to set the project url as below:

========================>

vskumar@ubuntu:~/test-git$ git remote set-url origin https://github.com/vskumar2017/git-test1.git

vskumar@ubuntu:~/test-git$

========================>

Please see the below content, I have pushed the code to my account VSKUMAR2017 as below:

 

==== Pushed code to github account ====>

vskumar@ubuntu:~/test-git$ git push origin master –force

Username for ‘https://github.com&#8217;: VSKUMAR2017

Password for ‘https://VSKUMAR2017@github.com&#8217;:

Counting objects: 20, done.

Compressing objects: 100% (16/16), done.

Writing objects: 100% (20/20), 1.85 KiB | 0 bytes/s, done.

Total 20 (delta 2), reused 0 (delta 0)

remote: Resolving deltas: 100% (2/2), done.

To https://github.com/vskumar2017/git-test1.git

 * [new branch]      master -> master

vskumar@ubuntu:~/test-git$

====================>

 

I have gone throuhg my account and saw the below url:

https://github.com/vskumar2017/git-test1

 

=== As per the below hist it is stored ===>

vskumar@ubuntu:~/test-git$ git hist

* e3fab98 2018-03-05 | first commit (HEAD -> master) [Vsk]

* 1fad32b 2018-03-05 | Added README file into mater [Vsk]

* fdc40ac 2018-02-24 | Revert “Committed test2.txt 3rd change” [Vsk]

* 69282e8 2018-02-24 | Committed test2.txt 3rd change (tag: v1) [Vsk]

* 6bfd9b0 2018-02-24 | Committed test1.txt 3rd change [Vsk]

* 2a7192d 2018-02-24 | Committed:Changes for test1.txt and test2.txt [Vsk]

* 56ccc1e 2018-02-24 | First Commit [Vsk]

vskumar@ubuntu:~/test-git$

=====================>

I have done one more push:

 

==== One more push to github ===>

vskumar@ubuntu:~/test-git$ git checkout master

Switched to branch ‘master’

vskumar@ubuntu:~/test-git$ git add .

vskumar@ubuntu:~/test-git$ git commit -m “A shell sample added “

[master c61b3dd] A shell sample added

 1 file changed, 3 insertions(+)

 create mode 100644 sh1.sh

vskumar@ubuntu:~/test-git$ git push origin master –force

Username for ‘https://github.com&#8217;: VSKUMAR2017

Password for ‘https://VSKUMAR2017@github.com&#8217;:

Counting objects: 3, done.

Compressing objects: 100% (2/2), done.

Writing objects: 100% (3/3), 299 bytes | 0 bytes/s, done.

Total 3 (delta 1), reused 0 (delta 0)

remote: Resolving deltas: 100% (1/1), completed with 1 local object.

To https://github.com/vskumar2017/git-test1.git

   e3fab98..c61b3dd  master -> master

vskumar@ubuntu:~/test-git$

=========================>

 

I have see the below content on my guthub web page of url:https://github.com/vskumar2017/git-test1

===== Message ===>

sh1.sh  A shell sample added just now

======>

 Hope you enjoyed it technically!!

END OF LAB SESSION FOR Git

 

 Vcard-Shanthi Kumar V-v3