Posts

Add Post

« Return to Posts

Cloning a git repository hosted on github.com or gitlab.com in Intel® DevCloud

Cloning a git repository hosted on github.com or gitlab.com in Intel® DevCloud

1.0. Git in three sentences

Git, developed by Linus Torvalds in 2005, is an open source version control software. Version control helps to manage and keep track of files ( - updates to the files that have been made in form of additions or subtractions) for the purpose of calling back specific versions in the future. Version control eases file collaboration, file comparison, file maintenance and file debugging.

1.1. GitHub and GitLab

Basically, GitHub¹ (not open source) and GitLab² (open source) are reliable cloud software development platforms that provide the services of git to host projects in repositories. Projects hosted include - code, documentation, static web pages, books, e.t.c. These platforms enable individuals and teams to manage changes to projects over time.

GitHub and GitLab share a common feature ( - they are both a cloud based git hosting service); however, they differ in other features such as software source type, repository limits, navigation, e.t.c.

To read more on the differences between github and gitlab see:

  1. Git vs Github: What’s the Difference and How to Get Started with Both: kinsta.com
  2. Difference Between Gitlab and Github: GeeksforGeeks.

¹ developed by Chris Wanstrath, P. J. Hyett, Tom Preston-Werner and Scott Chacon in 2008
² developed by Dmitriy Zaporozhets and Sytse Sijbrandij in 2013

image 1

image 2

1.2. Cloning a repository on GitHub and GitLab in Intel® DevCloud

This section focuses on using HTTPS (Hypertext Transfer Protocol Secure) and SSH (Secure Socket Shell) to clone a repository hosted on github and gitlab in Intel® DevCloud.

HTTPS and SSH are both network and data communication protocols between two different systems. They both make use of encryption to provide secure communication over a computer network.

HTTPS is a secure version of the HTTP protocol (a communication protocol between different communication systems [example : A Mifi and a laptop]), that is, it adds a layer of security to the HTTP protocol (thus, it is an extension of the HTTP protocol) . Security and authentication over a computer network in HTTPS is provided by an encryption protocol known as Secure Socket Layer / Transport Layer Security (SSL / TLS). The SSL uses a mechanism known as asymmetric public key infrastructure which uses a private and public key.

In SSH on the other hand, security is provided by a cryptographic network protocol. SSH provides secure remote login and other secure network / data communication services (- such as file transfer). It uses a strong password authentication and encrypted communication with a public key over an insecure network - thus providing security in data communication over an insecure channel (- such as the internet).

1.2.1. Differences between HTTPS and SSH for git operations

  1. Firewall restriction: HTTPS has a low firewall restriction and it is unlikely that a firewall will restrict communication over HTTPS. However, this is not the case in SSH; sometimes, firewalls and proxy servers refuse to allow an SSH connection, thus the user has to explicitly setup configurations to allow SSH communication (example: enabling SSH over HTTPS ports).

  2. Setup: HTTPS requires a repetitive confirmation - The user has to always confirm his/her username and password anytime a git operation is performed with HTTPS. In github, a Personal Access Token (PAT - is a 40 length character, too hard to remmeber) is required instead of a password. The user can however, opt to install and configure a credential manager to reduce the number of confirmation times. In gitlab, on the other hand, an originally set password can be used (this should be easy to remember), still there is an option for using a PAT for extra account security which again implies the need to setup a credential manager. The user also has to be extra careful when using a password or choosing an option for managing credentials with a credential manager.

SSH, on the other hand, does not require repetitive confirmation. It makes use of a public key shared between the local-remote systems(example: WSL-github) or remote-remote systems (example devcloud-github). This is much more safer than a password; the user needs to only know how to generate the public key locally and then manually add it to the SSH key section of the github / gitlab account. The only hassle here is for beginners who are just getting started with git, they might find it daunting to set up a SSH communication between their local system and remote system and thus go with https instead.

Read more about HTTPS and SSH:

  1. SSH Protocol in Git: toolsqa.com
  2. HTTP vs HTTPS: javatpoint.com
  3. SSH Meaning | SSH Protocol Definition: javatpoint.com
  4. SSH protocol: usage, versions and implementations: stackscale.com
  5. How to Generate Git SSH Keys: devconnected.com

1.2.2. Setting up HTTPS and SSH for git clone on the DevCloud

The following steps highlighted here are the steps I took to configure HTTPS and SSH for git cloning github and gitlab repositories in the Intel® DevCloud.

To follow the steps below make sure you set up and login to the devcloud on your preferred terminal for - Linux, Windows and macOS.

`ssh devcloud`
note: all commands should be executed on a computational node rather than the login node. This is because the login node uses a lightweight general-purpose processor and should not be used for the development or execution of programs; it's purpose is to connect or submit jobs to computational nodes.

1.2.2.1. GitHub

HTTPS:

   ` 1. Set up a Personal Access Token, PAT (see References [3]); use this token instead of password on prompt

Example:
`u00000@s***-n***:~$ git clone https://github.com/username/repository.git

Username for 'https://github.com': 'enter github username'

Password for 'https://username@github.com': 'enter PAT'`

SSH : using an SSH connection made over the HTTPS port

      1. Add SSH key to github settings. Settings >> Access >> SSH and GPG Keys
u00000@s***-n***:~$ cd .ssh

u00000@s***-n***:~/.ssh$ cat authorized_keys

Copy first key and paste in SSH box on github (do not forget to give your key a title)
The first authorized key is your public key also saved in id_rsa.pub file.
So you can also:

u00000@s***-n***:~/.ssh$ cat id_rsa.pub

Then copy and paste in SSH box on github

   ` 2. Test SSH over the HTTPS port possibility, run this SSH command:`

u00000@s***-n***:~/.ssh$ cd ~

u00000@s***-n***:~$ ssh -T -p 443 git@ssh.github.com

Hi username! You've successfully authenticated, but GitHub does not provide shell access.

  `  3. Enable SSH Connections over HTTPS:`

u00000@s***-n***:~$ cd .ssh

Create a configuration config file:

u00000@s***-n***:~/.ssh$ vi config

Enter the following into the file and write the file (save the file).

  `Host github.com
    Hostname ssh.github.com
    Port 443
    User git `
			
 `  4. Test if configuration works `

u00000@s***-n***:~/.ssh$ cd ~

u00000@s***-n***:~$ ssh -T git@github.com

Hi username! You've successfully authenticated, but GitHub does not provide shell access.

   ` 5. Test git clone with ssh`

u00000@s***-n***:~$ git clone git@github.com:username/repository.git

You are all set to clone github repositories with either https or ssh protocols on the Intel devcloud.

1.2.2.2. GitLab

HTTPS:

   ` 1. Use oriiginally created password or set up a Personal Access Token, PAT.

Example:
u00000@s***-n***:~$ git clone https://gitlab.com/username/repository.git

Username for 'https://github.com': 'enter gitlab username'

Password for 'https://username@github.com': 'enter password' / 'enter PAT'

NOTE: User should be able to enter PAT as password for Gitlab - I did not test this (I only tested with my password). But it should be the same as in github.

SSH

  1. Add SSH key to gitlab settings.
see here

u00000@s***-n***:~$ cd .ssh

u00000@s***-n***:~/.ssh$ cat authorized_keys

Copy first key and paste in SSH box on gitlab (do not forget to give your key a title)
The first authorized key is your public key also saved in id_rsa.pub.
So you can also:

u00000@s***-n***:~/.ssh$ cat id_rsa.pub

Then copy and paste in SSH box on gitlab

2. Test git clone with ssh
u00000@s***-n***:~/.ssh$ cd ~

u00000@s***-n***:~$ git clone git@gitlab.com:username/repository.git

You are all set to clone gitlab repositories with either https or ssh protocols on the Intel devcloud.

1.3. References

All links embedded in the article have been used as references. Below are references not mentioned in the text:

[1] Scott Chacon and Ben Straub, Pro Git, second edition. Apress®. [Online]. Available: here.

[2] GoLinuxCloud. "First time setting up git". [Online]. Available: here.

[3] Github Docs, "Creating a Personal Access Token". [Online]. Available: here.

[4] GitLab Docs, "Personal access tokens". [Online]. Available: here.

Thank you for reading!