通过ssh连接EC2到Git



有一个带有Git存储库的EC2实例,我需要通过ssh-key更新它。

我试着:

  1. 添加authorized_keys到GitHub。——比;不工作,而且方式不对。

  2. 创建一个新的ssh-key,将其添加到EC2控制台pair-key中并添加到GitHub中。由于ssh-add不能在EC2实例上工作,@Biswajit Mohanty建议我运行ssh -T git@github.com,并得到了正确的答案,但仍然得到"permission denied (publickey)"。致命:无法从远程存储库读取

我已经配置了.git/config:

sshCommand = "ssh -i ~/.ssh/id_rsa.pub"

[远程"origin"url = ssh://git@github.com/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

避免Permission错误:将私钥权限设置为

chmod 400 ./yourgitkey 

输入如下:

$ ssh -T git@github.com

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

> 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访问。

你现在准备好了!!

一般不添加authorized_keys到GitHub。您注册一个公共SSH密钥到您的GitHub用户配置文件,以便建立正确的身份验证。

如果您需要从EC2实例(意思是从EC2实例会话)推送到GitHub存储库,那么该会话应该包括~/.ssh/id_rsa~/.ssh/id_rsa.pub:私钥/公钥对,其中公共密钥如上所述注册到GitHub。

最新更新