I've recently started to enable 2FA (Two Factor Authentication) on most of my online accounts, including GitLab. But what happen when you try to clone a repository against https after that?
When I tried the first time I run the usual git clone:
git clone https://gitlab.com/username/project.git
but it didn't work, giving me this output:
Cloning into 'mypersonalbalance'... remote: HTTP Basic: Access denied remote: You must use a personal access token with 'read_repository' or 'write_repository' scope for Git over HTTP. remote: You can generate one at https://gitlab.com/profile/personal_access_tokens fatal: Authentication failed for 'https://gitlab.com/f.peluso/mypersonalbalance.git/'
I googled a little bit, finding that the problems was the 2 factor authentication, and then I found the following solution:
- Log in into the GitLab account;
- Go to the Settings section (at the moment, top right, hover the profile image and wait for the menu);
- Go to
- Now here you can create a temporary token; if you need to pull/push you must enable read_repository and write_repository flags.
- A token is shown in the page. Don't close or refresh the page, or you won't be able to retrieve the same token again!!!
- Save the token somewhere safe if you need to use it more than once (I needed only once, so I just copypasted it, and then deleted it).
After these steps you can clone the repository using
git clone https://oauth2:PERSONAL_ACCESS_TOKEN@gitlab.com/username/project.git
PERSONAL_ACCESS_TOKEN is the token you retrieved before.
GitLab explains that the tokens act like passwords after one enables the 2FA, so, in order to improve your security, you can manage one of more tokens to work with different repositories, devices and applications.
Latest comments (1)
More info: stackoverflow.com/a/51691209/1889607