EC2 |SSH有效,但GIT无效 [英] EC2 | SSH works but GIT does not

查看:84
本文介绍了EC2 |SSH有效,但GIT无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚设置了EC2服务器,并尝试使用git将本地文件从计算机推送到服务器.

I just set up an EC2 server and I am trying to push local files from my machine to the server with git.

在服务器上,我在/home/ec2-user/中初始化了一个git repo:

On the server, I initialized a git repo inside of /home/ec2-user/:

mkdir project.git
cd project.git
git init --bare

在客户端上,我使用以下命令:

git获取原始主文件

这将导致错误:

Permission denied (publickey, gssapi-keyex, gssapi-with-mic).
fatal: Could not read from remote repository
Please make sure you have the correct access rights and the repository exists.

这是我的本地存储库的配置文件的样子:(更改了网址的IP地址)

[core]
    repositoryformatversion = 0
    filemode = false
    bare = false
    logallrefupdates = true
    symlinks = false
    ignorecase = true
[remote "origin"]
    url = ec2-user@ec2-22-222-22-222.us-east-2.compute.amazonaws.com:project.git
    fetch = +refs/heads/*:refs/remotes/origin/*

此命令有效:(我可以ssh输入)

ssh ec2-user@ec2-22-222-22-222.us-east-2.compute.amazonaws.com

因为上面的命令有效,所以我认为我的PEM密钥不是问题,因为它可以使我SSH进入服务器.

Because the command above works, I would think that my PEM key is not the issue, seeing how it allows me to ssh into the server.

推荐答案

以防万一,我将使用完整的存储库路径开始测试:

Just in case, I would start testing with the full repository path:

git remote set-url origin ec2-user@ec2-22-222-22-222.us-east-2.compute.amazonaws.com:/home/ec2-user/project.git

这将确保Git正在查看您要访问的文件夹.

That would ensure that Git is looking at the folder you are trying to reach.

OP在聊天中使用

ssh -i "ec2-ohio.pem" ec2-user@ec2-22-222-22-222.us-east-2.compute.amazonaws.com

这意味着使用的私钥不是默认的%USERPROFILE%\.ssh \ id_rsa

That means the private key used is not the default %USERPROFILE%\.ssh\id_rsa

要让Git使用它,它需要通过URL和%USERPROFILE%\.ssh \ config

For Git to use it, it needs to refer to said key through the URL, and %USERPROFILE%\.ssh\config

首先,在配置文件中,声明一个ec2条目(您可以将其命名为任意名称,我使用的名称使我想起了远程服务器目标)

First, in the config file, declare an ec2 entry (you can call it any name you want, I use one which reminds me of the remote server target)

Host ec2
    Hostname ec2-22-222-22-222.us-east-2.compute.amazonaws.com
    User ec2-user
    IdentityFile ~/.ssh/ec2-ohio.pem

然后更改远程URL以使用该条目(及其关联的私钥)

Then change the remote URL to use that entry (and its associated private key)

git remote set-url origin ec2:/home/ec2-user/project.git

这篇关于EC2 |SSH有效,但GIT无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆