通过 ssh 将 EC2 连接到 Git

Nor*_*maN 2 github amazon-ec2 ssh-keys amazon-web-services

拥有一个带有 Git 存储库的 EC2 实例,我需要通过ssh-key.

我试过:

  1. 添加authorized_keys到 GitHub。--> 不起作用,而且方法不对。

  2. 创建一个新的 ssh-key,将其添加到 EC2 控制台对密钥中并添加到 GitHub。由于 ssh-add 在 EC2 实例上不起作用,@Biswajit Mohanty 建议我运行 ssh -T git@github.com,并得到了正确的答案,但仍然得到“权限被拒绝(公钥)”。致命:拉取时无法从远程存储库读取。

我已经配置了 .git/config ,因为它应该:

    sshCommand = "ssh -i ~/.ssh/id_rsa.pub"
Run Code Online (Sandbox Code Playgroud)

[远程“起源”] url = ssh://git@github.com/ArantecEnginheria/smartyplanet.git

关于成功执行“拉取”并将代码更新到该服务器的任何建议吗?

小智 7

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
Run Code Online (Sandbox Code Playgroud)

将 ./yourgitkey.pub 的内容复制到 GitHub https://github.com/settings/keys

添加新的 SSH 密钥并输入 ./yourgitkey.pub

为了避免权限错误:使您的私钥权限

chmod 400 ./yourgitkey 
Run Code Online (Sandbox Code Playgroud)

输入以下内容:

$ ssh -T git@github.com
Run Code Online (Sandbox Code Playgroud)

您可能会看到这样的警告:

> 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.
Run Code Online (Sandbox Code Playgroud)

如果是,则输入 yes:

你好用户名!您已成功通过身份验证,但 GitHub 不提供 shell 访问权限。

你现在准备好了!!!