【发布时间】:2019-11-23 05:53:14
【问题描述】:
我是 gitlab 的新手,这是我第一次使用 ssh。我可以生成 ssh 密钥并将其添加到我的帐户设置中。我可以通过 ssh 克隆 repo,我可以结帐到我的分支,但我仍然不能做的就是将我的更改推送到分支。这是我生成 ssh 密钥的一步一步,直到我尝试推送它(按照here 中的说明进行操作):
PS。我正在使用 Windows 10。
- 在终端上(以管理员身份),输入:
ssh-keygen -o -t rsa -b 4096 -C "myemail@example.com"。 - 按
Enter获取 ssh 密钥的默认路径 - 提供密码
- 在
~/.ssh/中创建配置文件。这是我在配置文件中写的:
Host ahostname
Hostname myhostname.com
User mygitlabusername
Port port
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
- 使用以下命令复制 ssh 密钥:
cat ~/.ssh/id_rsa.pub | clip - 将 ssh 密钥放入我的帐户设置中
- 然后,运行
ssh -T git@myhostname.com,结果如下:
The authenticity of host '[myhostname.com]:port ([123.456.789]:port)' can't be established.
ECDSA key fingerprint is SHA256:xxxx.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[myhostname.com]:port ([ipofmyshost]:port)' (ECDSA) to the list of known hosts.
Enter passphrase for key 'C:~/.ssh/id_rsa':
Welcome to GitLab, <myusername>!
- 然后我尝试克隆一个 repo:
git clone ssh://git@myhostname.com/repo.git - 但是,显然,在克隆时,它引用了另一个 IP 地址。例如,假设
ssh -T git@myhostname.com上的ipofmyhost是123.456.789。然后,当我克隆的时候,IP变成了123.456.781(抱歉我不能提真实IP)。所以,这是我在尝试克隆 repo 时得到的结果:
Warning: Permanently added the ECDSA host key for IP address '[123.456.781]:port' to the list of known hosts.
Enter passphrase for key '/c/.ssh/id_rsa':
- 但是,克隆完成了,然后我用
git checkout mybranchname结帐到我的分支 - 现在,我在我的分支机构。做一点改变。尝试
push,但这是我得到的错误:
git@myhostname.com: Permission denied (publickey).
fatal: Could not read from remote repository. Please make sure you have the correct access rights
and the repository exists.
我在这里错过了什么?我找到了this 问题,但很抱歉,我不明白接受的答案建议我如何解决这个问题。
更新
我尝试再次重新克隆,但在此之前,我删除了所有known_host。然后,再次执行git clone 而不使用ssh -T git@myhostname.com 进行测试,以避免创建新的IP 地址。但是,即使没有新的 IP 地址添加到 known_host,我在推送我的分支时仍然遇到同样的错误。
【问题讨论】: