拥有带有 Git 存储库的 EC2 实例,我需要通过
ssh-key
来更新它。
我尝试过:
将
authorized_keys
添加到 GitHub。 --> 不起作用,而且方法不对。
创建一个新的 ssh-key,将其添加到 EC2 控制台对密钥中并添加到 GitHub。由于 ssh-add 在 EC2 实例上不起作用,@Biswajit Mohanty 建议我运行 ssh -T [email protected],并得到了正确的答案,但仍然得到“权限被拒绝(公钥)”。致命:拉取时无法从远程存储库读取。
我已经配置了 .git/config :
sshCommand = "ssh -i ~/.ssh/id_rsa.pub"
[远程“起源”] url = ssh://[电子邮件受保护]/ArantecEnginheria/smartyplanet.git
对于成功执行“拉取”并将代码更新到该服务器有什么建议吗?
ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/.ssh/id_rsa): ./yourgitkey
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in ./yourgitkey
Your public key has been saved in ./yourgitkey.pub
将 ./yourgitkey.pub 的内容复制到 GitHub https://github.com/settings/keys
添加新的 SSH 密钥并输入 ./yourgitkey.pub
为了避免权限错误: 授予您的私钥权限
chmod 400 ./yourgitkey
输入以下内容:
$ ssh -T [email protected]
您可能会看到这样的警告:
> The authenticity of host 'github.com (IP ADDRESS)' can't be established.
> RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
> Are you sure you want to continue connecting (yes/no)?
Verify that the fingerprint in the message you see matches GitHub's RSA public key fingerprint.
如果是,则输入 yes:
您好用户名!您已成功通过身份验证,但 GitHub 未成功 提供 shell 访问。
你现在准备好了!!!
您通常不会向 GitHub 添加
authorized_keys
。您将公共 SSH 密钥注册到您的GitHub 用户配置文件,以便建立正确的身份验证。
如果您需要从 EC2 实例推送到 GitHub 存储库(即从 EC2 实例会话),则所述会话应包含
~/.ssh/id_rsa
和 ~/.ssh/id_rsa.pub
:私钥/公钥对,以及公钥如上所述注册到 GitHub。
这是如何在没有 github 参与的情况下完成的。我不想要它,我们也不被允许使用它。那么如何连接 git 存储库呢?