How To Install Git on Ubuntu 18.04


Step 1 — Update Default Packages

Logged into your Ubuntu 18.04 server as a sudo non-root user, first update your default packages.

  • sudo apt update

Step 2 — Install Git

  • sudo apt install git

Step 3 — Confirm Successful Installation

You can confirm that you have installed Git correctly by running this command and receiving output similar to the following:

  • git –version
Output
git version 2.17.1

Generating a new SSH key


Generating a new SSH key

  1. Open Terminal.
  2. Paste the text below, substituting in your GitHub email address.
    $ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

    This creates a new ssh key, using the provided email as a label.

    > Generating public/private rsa key pair.
  3. When you’re prompted to “Enter a file in which to save the key,” press Enter. This accepts the default file location.
    > Enter a file in which to save the key (/home/you/.ssh/id_rsa): [Press enter]
  4. At the prompt, type a secure passphrase. For more information, see “Working with SSH key passphrases”.
    > Enter passphrase (empty for no passphrase): [Type a passphrase]
    > Enter same passphrase again: [Type passphrase again]

aryan@aryan-VirtualBox:~$ cd .ssh
bash: cd: .ssh: No such file or directory
aryan@aryan-VirtualBox:~$ ssh-keygen -t rsa -b 4096 -C  aryan@xxxx.com
Generating public/private rsa key pair.
Enter file in which to save the key (/home/aryan/.ssh/id_rsa): 
Created directory '/home/aryan/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/aryan/.ssh/id_rsa.
Your public key has been saved in /home/aryan/.ssh/id_rsa.pub.
The key fingerprint is:

Adding your SSH key to the ssh-agent

Before adding a new SSH key to the ssh-agent to manage your keys, you should have checked for existing SSH keys and generated a new SSH key.

  1. Start the ssh-agent in the background.
    $ eval "$(ssh-agent -s)"
    > Agent pid 59566
  2. Add your SSH private key to the ssh-agent. If you created your key with a different name, or if you are adding an existing key that has a different name, replace id_rsa in the command with the name of your private key file.
    $ ssh-add ~/.ssh/id_rsa

Git Interview Questions


Git Exam Questions and answers

Which of the following should be done after installing Git on a system for the first time? (Choose all that apply)

– git config –global user.name “”
– git config –global user.email
Which Git command is used to stage changes for a commit?
– git add is used to stage changes for a commit.
What command is used to get changes into a remote repo?
– git push

What does the git checkout feature1 command do?
– It checks out a branch called feature1.

Git is an example of what type of tool?
– Source Control Management (SCM)
What is one way to configure a Git installation to authenticate with a remote repository like github.com?
– Upload a public ssh key to your github.com account.

Which command is used to obtain a local copy of a Git repository?
– git clone

Git Status, Git Commit, Git Add


To Edit File in Git

GitAddChange
cd to directory: vi views/index.jade (File Name)
Edit the file in VI Editor and save :qw!

To see Status: git status

# On branch master
# Changes to be committed:
# (use “git reset HEAD <file>…” to unstage)
#
# modified: views/index.jade
#

To Commit

git commit -m “change header text

[master 43185e0] change header text
1 file changed, 2 insertions(+), 2 deletions(-)

 

Setting up Priate Key Access


Setting up Priate Key Access\

An easy way to authenticate with remote git server like GitHub is to use an ssh key pair.

On a CentOs environment, you can generate an ssh key pair like this
ssh-keygen -t rsa -b 4096

Setting up Priate Key Access

After generating the key pair, copy the contents of ~/.ssh/id_rsa.pub.

[root@aryan-34252e5f2 ~]# ssh-keygen -t rsa -b 4096
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:mTVGOKHkJ7uWbiDVtm0cecEJfTEH53g1mnu8VsPnif4 root@aryan-34252e5f2.mylabserver.c om
The key’s randomart image is:
+—[RSA 4096]—-+
| . o*..+oo..|
| o .o.= .*o..|
| .+ .o+o.oo |
| . o+o=.. .+ |
| . ..+So . =o|
| . . .o+ o.*|
| . .+. . +.|
| o. . . |
| .. ..E |
+—-[SHA256]—–+