How to Solve Git Clone Authentication Issues with a Personal Access Token (PAT)?

How to Solve Git Clone Authentication Issues with a Personal Access Token (PAT)?

While working on cloning a repository from a GitHub Enterprise server, I encountered an SSL issue. When I tried to clone the repository using HTTPS, Git prompted me to enter credentials, but I wasn’t using a typical username and password combination because I log in using Microsoft 365 credentials. Here’s the full breakdown of the issue and how I resolved it using a Personal Access Token (PAT).

The Problem: SSL and Authentication Prompts

When I first attempted to clone the repository using HTTPS, I encountered two major issues:

  1. SSL Certificate Error: The GitHub Enterprise server was using a self-signed SSL certificate, which caused Git to fail the operation due to an SSL certificate verification error.
  2. Authentication Prompt: Even after bypassing the SSL issue, Git prompted me for a username and password. Since I use Single Sign-On (SSO) with Microsoft 365, I didn’t have a traditional username and password for the repository.

At this point, I couldn’t complete the clone operation because of the self-signed SSL certificate and the absence of standard credentials.

Step 1: Bypassing the SSL Certificate Issue

To temporarily work around the SSL certificate problem, I ran the following Git command, which disables SSL verification:

git -c http.sslVerify=false clone https://yourcompany.domain/your-team/your-repo.git .

This command tells Git to ignore the SSL certificate check and proceed with the clone operation. However, it didn’t solve the authentication issue, as Git was still prompting me for a username and password.

Step 2: Resolving the Authentication Issue with a Personal Access Token (PAT)

Because I was logging into my GitHub Enterprise account using Microsoft 365 credentials (via SSO), I didn’t have a typical username/password combination to provide when prompted. The solution was to use a Personal Access Token (PAT), which GitHub provides for secure authentication in such cases.

What is a Personal Access Token (PAT)?

A Personal Access Token (PAT) is a more secure way to authenticate when using Git over HTTPS. It works like a password but is more flexible and secure. You can generate a PAT and use it instead of a password when Git prompts for credentials. You can control its permissions (known as scopes), making it a safer option.

How to Generate a PAT

  1. Log into your GitHub Enterprise account.
  2. Go to Settings > Developer settings > Personal access tokens.
  3. Click Generate new token and select the appropriate permissions (scopes). For repository access, you will typically need the repo scope.
  4. Copy the generated token (PAT) and save it in a secure place (you won’t be able to view it again after this point).

Using the PAT to Clone the Repository

Once I had the Personal Access Token, I went back to my terminal. When Git prompted me for a username, I entered my email address (associated with the Office 365 login). When it prompted for a password, I pasted the PAT instead of a password:

Username for 'https://yourcompany.domain': [email protected]
Password for 'https://[email protected]@yourcompany.domain': <paste-your-PAT-here>

After this, the clone operation worked perfectly, and I had access to the repository.


Posted

in

by