Today I've enabled Gitlab's 2nd-factor authentication. After that, since I logged in the Gitlab website, I need to use my cell phone to pass a 6-digits plus my password, that's good, it makes me feel safe.
However, when I use the general operations, for example git clone some-repo.git
, I got the error:
Cloning into 'some-repo'... remote: HTTP Basic: Access denied remote: You must use a personal access token with 'api' scope for Git over HTTP. remote: You can generate one at https://gitlab.com/profile/personal_access_tokens fatal: Authentication failed for 'some-repo.git'
Then I try existing cloned local repo, using git pull
, the same error occurs. Before I enabled the 2nd-factor authentication, all the above operation worked fine.
Flowing the above error's instructions, I went to the mentioned address: https://gitlab.com/profile/personal_access_tokens. I created the following token, and save the token's key.
However, I don't know what to do with this key. Can someone tell me how to use this key to enable the basic operations like git pull
, git clone
, git push
etc...
I had many repos on local before I enabled the 2nd-factor authentication. I want these to work too.
In the upper-right corner of any page, click your profile photo, then click Settings. In the "Access" section of the sidebar, click Password and authentication. Under "Two-factor authentication", click Enable two-factor authentication. Under "Two-factor authentication", select Set up using SMS and click Continue.
all tiers. Two-factor authentication (2FA) provides an additional level of security to your users' GitLab account. When enabled, users are prompted for a code generated by an application in addition to supplying their username and password to sign in.
As explained in using gitlab token to clone without authentication, you can clone a GitLab repo using your Personal Access Token like this:
git clone https://oauth2:[email protected]/yourself/yourproject.git
As for how to update your existing clones to use the GitLab Personal Access Token, you should edit your .git/config
file in each local git directory, which will have an entry something like this:
[remote "origin"] url = https://[email protected]/yourself/yourproject.git
Change the url
:
[remote "origin"] url = https://oauth2:[email protected]/yourself/yourproject.git
Now you can continue using this existing git clone as you did before you enabled 2FA.
I used the generated Personal Access Token as the password when prompted to enter credentials.
This allowed me to just use the standard Git Clone syntax without entering anything additional.
When you generate, copy the token. This is the password that will be stored in Credential Manager when you clone. Use that as your password instead of your git password.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With