How to connect GitHub from Linux using private key

  1. Login to ternimal 
  2. Create ssh public key using the following command 
    ssh-keygen -t rsa -b 4096 -C ""
    Will ask for id.rsa file number. jus hit enter.
    Next will ask for passphrase, If you need to secure you git repository provide a phrase. Otherwise just hit enter. (remember it, will ask every time when you try to commit and push the code)
  3. ~/.ssh/ file is created in your user home directory.
  4. using vi ~/.ssh/ or gedit ~/.ssh/ edit it and copy the content of the file.
  5. Login in to
  6. Select your repository => "Settings" in top menu.=> Click "Deploy keys"
  7. Input "Title" for your reference, paste the copied key in to "Key" textarea.
  8. It will ask you to confirm you account password.
    Now your are ready to connect to you repository.
  9. Now create a folder and using "git clone" command.

During git push it will ask for passphrase, If you provided during the private key generation.(@Step 2)

Tags: Linux, GitHub, SSH Private Key, GIT

Useful GIT commands

Here are the list of major git commands and their short descriptions.

git init

    Initializes a git repository – creates the initial ‘.git’ directory in a new or for an existing project.

git config

    Configure git with username,  password, email-id, and server details. It can be configured --global / --system / --local

git clone

    Download a copy of project from GIT server (Eg: git clone

git add

    Add the files to local repository. Eg: git add file.txt / git add . - remove all changed files.

git rm

    Remove files from local repository. Eg: git rm file.txt / git rm . - remove all changed files.

git commit

    Save the added files to local repository, creates a new commit object pointing to it and sets the branch to point to that        new commit. Eg: git commit -m ‘committing added changes’ git commit -a -m ‘committing all changes, equals to git add      and git commit’

git status

    Show the current status of changes. Changed not add/commited/push to local.

git branch

    Show the list of local branches. In the output it will highlight the current active branch.

git push

    Push the commited changes from local repository to GIT server. Need to authenticate using username/password if it's       a private.

git checkout

    Switch for one branch to another. need to mention the branch name. Eg: git branch

git pull

    Fetches the files from the remote repository and merges it with your local one. This command is equal to the git fetch        and the git merge sequence. Example: git pull origin.

git diff

    Generates patch files or statistics of differences between paths or files in your git repository, or your index or your              working directory. Example: git diff

Tags: GIT Commands, GIT

Use full Linux commands

Here are some of Linux usefull general commands

View all Environment variables

env command can be used to view all enviroment variable and its value for current logged user via terminal.

ubuntu@ip-xx-xx-xx-xx:~/maven/JavaProj$ env
SSH_CLIENT= 54904 22

Set Environment Variables on Linux

You can modify each environmental or system variable using the export command. Set the PATH environment variable to include the directory where you installed the bin directory with perl and shell scripts:

export ANT_HOME=/path/to/ant/dir
export PATH=${PATH}:${ANT_HOME}/bin:${JAVA_HOME}/bin

Above command will set value for variable ANT_HOME and append it to PATH

Unset a environment variable

Enviroment variable can be removed from current user environment dynamically without any reboot and affecting other user or same user any other environment using unset command as follows

unset ANT_HOME

Above command remove the ANT_HOME variable and it's value from current user enviroment without affecting same user other enviroment.

View verbose output for git command

Normal git command will not show the output of communication performed with GIT server while executing clone/pull/push command. To view the output of full culr response header value, we need to set the verbose output as true while executing every git command as follows.

GIT_CURL_VERBOSE=1 git clone

command will output the request and response for curl command performand by git command.

ubuntu@ip-xxx-xx-xx-xxx:~/maven/JavaProj$ GIT_CURL_VERBOSE=1 git pull
* Couldn't find host in the .netrc file; using defaults
*   Trying
* Connected to ( port 443 (#0)
* found 148 certificates in /etc/ssl/certs/ca-certificates.crt
* found 596 certificates in /etc/ssl/certs
* ALPN, offering http/1.1
* SSL connection using TLS1.2 / ECDHE_RSA_AES_128_CBC_SHA1
*        server certificate verification OK
*        server certificate status verification SKIPPED
*        common name: (matched)
*        server certificate expiration date OK
*        server certificate activation date OK
*        certificate public key: RSA
*        certificate version: #3
*        subject:
*        start date: Thu, 14 Dec 2017 00:00:00 GMT
*        expire date: Fri, 14 Dec 2018 12:00:00 GMT
*        issuer: C=US,O=Amazon,OU=Server CA 1B,CN=Amazon
*        compression: NULL
* ALPN, server did not agree to a protocol
> GET /v1/repos/PHPWordPress/info/refs?service=git-upload-pack HTTP/1.1
User-Agent: git/2.7.4
Accept: */*
Accept-Encoding: gzip
Accept-Language: en-US, *;q=0.9
Pragma: no-cache
< HTTP/1.1 401 Unauthorized



Tags: GIT, CURL, Env, Export