在gitlab上获取权限被拒绝(公钥)
我的问题是我不能从GitLab推送或获取。但是,我可以克隆(通过HTTP或SSH)。我在尝试推送时出现以下错误: 权限被拒绝(公钥)致命:无法从远程存储库读取 从我所看到的所有线索来看,以下是我所做的:在gitlab上获取权限被拒绝(公钥),git,ubuntu,ssh,gitlab,Git,Ubuntu,Ssh,Gitlab,我的问题是我不能从GitLab推送或获取。但是,我可以克隆(通过HTTP或SSH)。我在尝试推送时出现以下错误: 权限被拒绝(公钥)致命:无法从远程存储库读取 从我所看到的所有线索来看,以下是我所做的: 在我的计算机上设置SSH密钥并将公钥添加到GitLab 完成用户名和电子邮件的全局配置 通过SSH和HTTP进行克隆,以检查它是否能够解决问题 完成了ssh-Tgit@gitlab.com命令 如果您对如何解决我的问题有任何见解,我们将不胜感激。我让gitlab与docker一起运行,这就是
- 在我的计算机上设置SSH密钥并将公钥添加到GitLab
- 完成用户名和电子邮件的全局配置
- 通过SSH和HTTP进行克隆,以检查它是否能够解决问题
- 完成了ssh-Tgit@gitlab.com命令
如果您对如何解决我的问题有任何见解,我们将不胜感激。我让gitlab与docker一起运行,这就是我为解决我的问题所做的 发现docker/var/log/gitlab/sshd/current内部多次出现一条消息: 身份验证被拒绝:文件/var/opt/gitlab/.ssh/authorized_密钥的所有权或模式错误 在此之后,我将该文件的所有权从99:users更改为git:users,其中包含: chown git:用户授权的密钥
我找了很多才找到这个。这对我来说非常好
ssh-keygen
.ssh
文件夹id\u rsa.pub
。在记事本上打开它。从中复制所有文本现在试一试,它肯定会工作。确保您没有运行
sudo git clonegit@gitlab.com:project/something.git
,否则ssh将查找/root/.ssh
,而不是您上载的密钥~/.ssh/id\u rsa
步骤1:
在~/.ssh/config
文件中添加了一个如下所示的配置文件
User git
Hostname gitlab.com
IdentityFile ~/.ssh/id_rsa_gitlab
TCPKeepAlive yes
IdentitiesOnly yes
步骤2:只需克隆git repo而不使用sudo。
文档:我认为简单的解决方案是向身份验证代理添加私钥(如果您的密钥不是
~/.ssh/id\u rsa
)
ssh添加~/.ssh/
基本上是让ssh代理处理它
另外,您可以。在我的例子中,这不是gitlab的问题,而是sshd配置的问题。除了用户列表之外,ssh服务器不允许连接。远程连接到gitlab的用户git不在该列表中。所以,在做其他事情之前先检查一下这个
您可以在/etc/ssh/sshd\u config
中检查ssh服务器配置。如果您有一行带有选项AllowUsers
,请将git添加到该行:
AllowUsers user1 user2 user3 git
我是这样解决的
使用以下命令为Windows生成密钥:
ssh-keygen -t rsa -C "your.email@example.com" -b 4096
但问题是,在运行此命令后,它弹出一行:
“输入保存密钥的文件(/c/Users/xxx/.ssh/id\u rsa):”
在这里,我只给出了文件名,因为我的密钥被保存在我的pwd中,而不是给定的位置。当我执行“git clone”时,它假设密钥位于“/c/Users/xxx/.ssh/id_rsa”位置,但没有找到它,因此抛出了错误
在生成密钥时,生成了2个文件,例如“file1”和“file1.pub”。我将这两个文件重命名为
file1 -> id_rsa
及
并将两者放置在位置“/c/Users/xxx/.ssh/”
转到终端,再次重新生成ssh密钥。键入ssh-keygen
。它会询问您要将其保存在哪里,键入路径
然后将公钥复制到gitlabs平台。它通常以ssh rsa开头。如果您使用的是Linux或macox,只需在终端中尝试以下操作:
ssh添加-l
如果未返回任何内容,请尝试以下操作:
ssh添加
它必须在~/.ssh/id\u rsa中创建标识
重试后:
ssh添加-l
它必须返回您的身份,所以在重试克隆后,它必须工作
注意:不要忘记在您的个人资料gitlab中添加ssh密钥
谢谢我将我的~/.ssh/id\u rsa.pub
添加到我的GitLab设置中的已知ssh密钥列表中。这为我解决了问题。:-) 在我的例子中,它在WSL(Linux的Windows子系统)中不起作用
当我启动WSL时,我必须
- 启动ssh-agent \
eval$(ssh代理-s)
- 将密钥添加到ssh代理:
ssh add~/.ssh/id\u rsa
- 如果出现提示,请输入密码
现在连接工作了。
我们可以使用ssh-T来测试这一点git@github.com
注:
- 允许我们重用WSL中加载的ssh密钥
- 详细说明:
要执行的步骤,得到了相同的错误,但我修复了它。
Gitlab需要ssh rsa,下面是运行ssh for rsa的代码
ssh-keygen-o-t rsa-b4096-C”name@gmail.com“
name@gmail.com你的gitlab帐户是电子邮件吗
它会提示您输入,所以在下面的代码提示后只需按enter键
输入保存密钥的文件(/home/yourDesktopName/.ssh/id\u rsa):
它会再次提示您输入,所以在下面的代码提示后只需按enter键
输入密码短语(无密码短语为空):
它会再次提示您最后一次输入,所以在下面的代码提示后只需按enter键
再次输入相同的密码短语:
您将显示您的ssh rsa generate
登录到您的Gitlab帐户并转到右侧的导航栏,您将获得设置,在左侧的侧栏中,您将获得ssh密钥。进去吧
在提示您输入的上方查看,您将获得路径
file1 -> id_rsa
file1.pub -> id_rsa.pub
ssh-keygen -t ed25519 -C "your-email-id@gmail.com"
ssh-add ~/my-pc/Desktop/.ssh/ed25519
To create a new SSH key pair:
1. Open a terminal on Linux or macOS, or Git Bash / WSL on Windows.
2. Generate a new ED25519 SSH key pair: ssh-keygen -t ed25519 -C "email@example.com"
2.1 Or, if you want to use RSA: ssh-keygen -o -t rsa -b 4096 -C "email@example.com"
3. Next, you will be prompted to input a file path to save your SSH key pair to... use the suggested path by pressing Enter
4. Once the path is decided, you will be prompted to input a password to secure your new SSH key pair. It's a best practice to use a password, but it's not required and you can skip creating it by pressing Enter twice.
5. Copy your public SSH key to the clipboard by using one of the commands below depending on your Operating System:
macOS: pbcopy < ~/.ssh/id_ed25519.pub
WSL / GNU/Linux (requires the xclip package): xclip -sel clip < ~/.ssh/id_ed25519.pub
Git Bash on Windows: cat ~/.ssh/id_ed25519.pub | clip
6. Navigating to SSH Keys and pasting your public key in the Key field
7. Click the Add key button
$ sudo gitlab-rake gitlab:shell:setup
Match User git # Apply the AuthorizedKeysCommands to the git user only
AuthorizedKeysCommand /opt/gitlab/embedded/service/gitlab-shell/bin/gitlab-shell-authorized-keys-check git %u %k
AuthorizedKeysCommandUser git
Match all # End match, settings apply to all users again
# Debian or Ubuntu installations
sudo service ssh reload
# CentOS installations
sudo service sshd reload