当前位置:   article > 正文

【GitLab】-HTTP Basic: Access denied.remote:You must use a personal access token_the provided password or token is incorrect or you

the provided password or token is incorrect or your account has 2fa enabled

写在前面

  本文简要说明GitLab配置accessToken以及双因子认证(Two-factor authentication)



一、场景描述

  在使用账号和密码的方式拉取公司GitLab代码时,遇到了以下问题HTTP Basic: Access denied. The provided password or token is incorrect or your account has 2FA enabled and you must use a personal access token instead of password.
在这里插入图片描述

说明:全文中涉及到的地址均为模拟环境
git clone http://192.168.41.130:9001/gitlab/a-learn/design-pattern.git
  • 1
  • 2

咱不得不说,这个GitLab提示是真友善,直接说出了问题所在:
1、密码或者token错误(首先排除密码错误,不可能多次输入都错误)
2、账号启用了2FA
3、你必须使用个人的access token 来代替密码

那它提示的这个2FA和personal access token是什么东西?接下来就一探究竟。


二、具体步骤

1.环境说明

名称说明
Windows版本Win10/X64
Git版本2.31.1
GitLab版本15.10.2

2.配置accessToken

登录GitLab,Edit Profile -》Access Tokens

先看说明文字:
“Personal Access Tokens
You can generate a personal access token for each application you use that needs access to the GitLab API.

You can also use personal access tokens to authenticate against Git over HTTP. They are the only accepted password when you have Two-Factor Authentication (2FA) enabled.”

仔细看,什么是access Tokens?access token可以用来访问GitLab API,可以通过HTTP的方式认证,当启用Two-Factor Authentication (2FA)双因子认证时,只能通过这种方式作为密码访问。

好家伙,问题迎刃而解,那就添加一个access Token
在这里插入图片描述

填写Token name、Expiration date、Select scopes -》Create personal access token即可
在这里插入图片描述
复制出token,glpat-UFBSgkqh8Sk6JQf9yTU8

3.克隆项目

那怎么使用accessToken呢?

格式:git clone http://{username}:{token}@{URL}
git clone http://oauth2:glpat-UFBSgkqh8Sk6JQf9yTU8@192.168.41.130:9001/gitlab/a-learn/design-pattern.git
  • 1
  • 2

在这里插入图片描述
windows 环境,控制面板 -》用户账户 -》管理凭据
通过凭据,可以看到用户名确实是oauth2
在这里插入图片描述

4.双因子认证

管理员登录,左上角选中Admin
在这里插入图片描述
在Admin Area左侧侧边栏,选择Settings -》General
在这里插入图片描述
选择Sign-in restrictions Expand,勾选Two-factor authentication,save and change,跳转到绑定页面(新用户登录直接会跳转这个页面)
在这里插入图片描述

下载Google认证器,下面这个样子

打开Goole认证器,扫描二维码(会将当前登录用户的邮箱进行绑定,展示出6位数字密码)。输入当前用户登录密码和Google认证器上的6位数字码,即可(默认会生成10个认证码)

退出,再次登录的时候就需要二次输入认证
在这里插入图片描述


三、参考资料

GitLab remote: HTTP Basic: Access denied and fatal Authentication


写在后面

  如果本文内容对您有价值或者有启发的话,欢迎点赞、关注、评论和转发。您的反馈和陪伴将促进我们共同进步和成长。

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
相关标签
  

闽ICP备14008679号