修复"HTTP Basic:Access Deanied"和Gitlab错误的"致命验证失败"
当将代码推向GitHub上的远程存储库时,报错:
Hyman@theitroad:~/Documents/Local-Code$git push -u origin master Username for 'https://gitlab.com': gitlab_profile_username Hyman@theitroad': remote: HTTP Basic: Access denied fatal: Authentication failed for 'https://gitlab.com/gitlab_account_username/gitlab_repository/'
Gitlab处理"远程:HTTP基本:访问拒绝访问"错误
提供一些关于此错误的根本原因的线索的主线是这个:
remote: HTTP Basic: Access denied
我为什么这么说?
因为Gitlab存储库正在使用HTTPS。
它希望在系统和存储库之间具有安全的连接。
现在,它应该不自动使用HTTPS吗?
Gitlab已更改其策略,现在它希望我们使用自己的SSH密钥与Gitlab存储库进行身份验证。
换句话说,要将本地系统从本地系统推送到远程Gitlab存储库,必须创建一个SSH键对并将公钥添加到Gitlab配置文件。
我正在使用Linux,因此Linux上最好的步骤。
如果我们使用的是Windows或者MacOS,则应采取提示并检查操作系统上的方式如何进行操作。
首先检查是否已有SSH键:
ls ~/.ssh/id_rsa.pub
如果我们没有它,请使用下一节创建它在此之后跳转到该部分。
创建SSH键(如果我们没有已经拥有)
我正在使用Ubuntu,所以步骤适用于Ubuntu。
如果我们使用的是其他发行版,则步骤可能会或者可能不会不同。
打开终端并使用以下命令:
ssh-keygen
我们应该看到这样的输出:
Generating public/private rsa key pair. Enter file in which to save the key (/user_home/.ssh/id_rsa):
按ENTER键并使用默认选择。
我们可能会要求我们输入密码以保护SSH密钥。
如果设置密码,每次尝试使用生成的SSH键进行SSH连接时都必须输入它。
我们可以或者可能无法为SSH密钥设置密码。
10个可操作的SSH硬化提示,用于保护Linux服务器
担心Linux服务器的安全性?
了解一些易于在保护SSH上实现提示,并使Linux服务器更安全。
我们可以添加多个SSH键。
如果我们有多台计算机,那就很正了。
检查我们是否可以立即将代码推送给Gitlab
因此,我们将SSH密钥添加到Gitlab配置文件中。
现在应该擅长。
是时候验证了。
尝试再次推出代码。
看它是否有效。
通常,如果它成功,我们应该看到这样的输出:
Hyman@theitroad:~/Documents/Local-Code$git push -u origin master Username for 'https://gitlab.com': gitlab_account_username Password for 'https://Hyman@theitroad': Enumerating objects: 127, done. Counting objects: 100% (127/127), done. Delta compression using up to 4 threads Compressing objects: 100% (122/122), done. Writing objects: 100% (127/127), 401.30 KiB | 6.37 MiB/s, done. Total 127 (delta 14), reused 0 (delta 0) remote: Resolving deltas: 100% (14/14), done. To https://gitlab.com/gitlab_account_username/gitlab_repository.git * [new branch] master -> master Branch 'master' set up to track remote branch 'master' from 'origin'.
还是看到错误?介意Gitlab个人资料用户名与帐户用户名之间的区别!
我学会了这件事。
Gitlab有两个用户名:配置文件用户名和帐户用户名。
我们可以轻松更改配置文件用户名,而不会产生任何后果。
但更改帐户用户名可能是灾难性的。
帐户用户名是我们将在Gitlab存储库的URL中看到的:
https://gitlab.com/gitlab_account_username/repository_name
在从其创建新的Gitlab存储库时,Gitlab在个人计算机上使用Git配置设置中的配置文件用户名建议。
我这样做了,我试图在将代码推到存储库时使用相同的个人资料名称。
不出所料,即使在添加SSH密钥后也被拒绝:
Hyman@theitroad:~/Documents/Local-Code$git push -u origin master Username for 'https://gitlab.com': gitlab_profile_username Password for 'https://gitlab_profHyman@theitroad': remote: HTTP Basic: Access denied fatal: Authentication failed for 'https://gitlab.com/gitlab_account_username/gitlab_repository.git/'
因此,诀窍是在此处使用Gitlab帐户用户名。
当我这样做时,向远程Gitlab存储库的推送成功。