Access Gitlab from local using two factor token
How to push changes to Gitlab, when two factor authentication is enabled.
When two factor authentication is enabled in Gitlab
, we get authentication error when we try to push changes from our local to Gitlab.
The error look like something as shown below,
remote: HTTP Basic: Access denied
To be able to push to Gitlab
, we need to setup personal token in Gitlab
and set it up in our local Git project as well.
-
In
Gitlab
go to User Profile at top right end, -
Then select
Access Tokens
- The Personal Access Token page will open. Here create a personal token. Select all
scopes
and clickCreate personal access token
-
A unique personal access token will be generated. Keep this saved somewhere safe. This will be required in future
-
Now go to your project and copy the
HTTPS
GITLAB
url.
- Now open git bash in your local and type below,
git clone https://oauth2:PERSONAL_ACCESS_TOKEN@gitlab.com/username/project
This should now enable you to push code to Gitlab
.
These tokens act as passwords. You can have different tokens set for different projects as well.