将Git配置为从特定位置使用.pem密钥

将Git配置为从特定位置使用.pem密钥,git,ssh,Git,Ssh,每当我尝试执行“git pull origin master”时,我都会得到(它不是Github): 权限被拒绝(公钥) 我能够SSH到我的AWS EC2 Linux服务器中,它有一个空的存储库,当我收到上面提到的权限错误时,我正试图从中提取该存储库 我确实已将公钥复制到该服务器,因为我可以通过ssh成功登录,但必须执行以下操作: ssh-i/location/of/pemkey/mykey.pem ec2-user@ec2-12-34-56-78.美国东部计算机公司amazonaws.com

每当我尝试执行“git pull origin master”时,我都会得到(它不是Github):

权限被拒绝(公钥)

我能够SSH到我的AWS EC2 Linux服务器中,它有一个空的存储库,当我收到上面提到的权限错误时,我正试图从中提取该存储库

我确实已将公钥复制到该服务器,因为我可以通过ssh成功登录,但必须执行以下操作:

ssh-i/location/of/pemkey/mykey.pem ec2-user@ec2-12-34-56-78.美国东部计算机公司amazonaws.com

我需要配置Git以使用我的“.pem”密钥。 如何设置Git以使用我的“.pem”键?

Git(1)
手册页:

   GIT_SSH
       If this environment variable is set then git fetch and git push
       will use this command instead of ssh when they need to connect to a
       remote system. The $GIT_SSH command will be given exactly two or
       four arguments: the username@host (or just host) from the URL and
       the shell command to execute on that remote system, optionally
       preceded by -p (literally) and the port from the URL when it
       specifies something other than the default SSH port.

       To pass options to the program that you want to list in GIT_SSH you
       will need to wrap the program and options into a shell script, then
       set GIT_SSH to refer to the shell script.

       Usually it is easier to configure any desired options through your
       personal .ssh/config file. Please consult your ssh documentation
       for further details.
以我个人的经验,在
.ssh/config
中添加主机设置的一次性成本造成了很大的差异,即使对于只有用户名不同的主机也是如此。

我从中得到了这个答案,但这不是主要的答案。 这里列出的说明对我更有用

调整~/.ssh/config并添加:

Host example
Hostname example.com
User myuser
IdentityFile ~/.ssh/other_id_rsa
现在使用ssh主机别名作为存储库:

$ git remote add origin example:repository.git

$ git pull origin master

它应该使用另一个rsa密钥

好的,为什么要将git配置为使用.pem密钥?如果您成功地生成了一个ssh密钥,只需将公钥复制到服务器上即可。很好,这就是我的想法,但是我的.ssh/config文件在哪里?@confusedeer
~/.ssh/config
您让我走上了正确的轨道,我会将您的答案标记为答案,但我会添加我自己的答案以供澄清,因为还有一些其他的步骤需要完成。我终于把它拔出来了。谢谢
1. touch ~/.ssh/config
2. chmod 644 ~/.ssh/config
3. vim ~/.ssh/config
    #write next codeline
    host ec2-ip.eu-west-1.compute.amazonaws.com
    IdentityFile ~/Documents/ec2-user.pem

git clone git@ec2-ip.eu-west-1.compute.amazonaws.com:/home/git/my-repo.git