向亚马逊 ec2 推送提交时权限被拒绝(公钥) [英] Permission denied (publickey) when pushing commit to amazon ec2

查看:29
本文介绍了向亚马逊 ec2 推送提交时权限被拒绝(公钥)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这里有很多类似的问题(在发布这个问题之前我阅读了很多),但是这个问题不同,所以请多待会儿.

几天前,我在亚马逊 ec2 上配置了我的远程 git 存储库.经过几个小时的努力,我让它工作了,并且能够在那里push文件.我使用它一两天没有任何问题地向它推送资源(我正确地看到了每个更新).

今天,由于某种原因,我无法从本地机器向它推送任何内容.

git push deploy 最终得到以下错误消息(我在尝试获取有关部署的信息时看到的相同:git remote show deploy):<块引用>

警告:push.default 未设置;它的隐含价值正在改变Git 2.0 从匹配"到简单".压制这条消息并在默认更改后保持当前行为,请使用:git config --global push.default 匹配要立即取消此消息并采用新行为,请使用:git config --global push.default 简单请参阅git help config"并搜索push.default"以获取更多信息.('simple' 模式是在 Git 1.7.11 中引入的.使用类似的模式如果您有时使用旧版本的 Git,则使用当前"而不是简单")

权限被拒绝(公钥).致命:无法从远程存储库读取.请确保您拥有正确的访问权限并且存储库存在.

它的第一部分(在许可被拒绝之前)我以前能够看到,但当时它仍然正确地推动了一切.

Deploy 存在是因为我可以用 git remote -v 清楚地看到它:

deploy ssh://ubuntu@X.X.X.X/home/ubuntu/repo (fetch)部署 ssh://ubuntu@X.X.X.X/home/ubuntu/repo(推送)

我可以正确 ssh 到我的服务器,我的私钥也有 0400 权限.在两台机器上我都有 ubuntu 12.04 LTS.

我认为我的公钥可能有问题,所以我继续使用私钥重新创建它:ssh-keygen -y -f key.pem >密钥.pub.基于它的 sha,它与我之前的公钥相同:sha1sum key_prev.pub = sha1sum key.pub

我还是去了服务器,并为授权密钥添加了一个新密钥.

仍然没有变化.我不能推任何东西.谁能告诉我这里有什么问题,为什么会发生?我需要对本地 .ssh/known_hosts 做些什么吗?

也在其中一个答案中,我发现了以下内容:

<块引用>

请注意,重启实例后,dns 名称发生了变化.我为此堕落了好几次.密钥文件仍然有效,但服务器名称"已更改.

我实际上重新启动了我的机器,所以我认为这是高度相关的.问题是我不明白我现在应该改变什么.

阅读 VonC 的回答后.

我无法通过执行 ssh ubuntu@XXXX 来 ssh 到服务器(我得到了 Permission denied(publickey).),但我可以用 做到这一点ssh myAlias,其中myAlias定义在~/.ssh/config

托管 myAlias主机名 X.X.X.X用户 ubuntuIdentityFile path/to/mypem/file.pem

当我完成 git config --global push.default simple 时,我在执行 git push deploy 时遇到了另一个问题:

<块引用>

fatal:当前分支 master 没有上游分支.推当前分支并将远程设置为上游,使用

git push --set-upstream deploy master

我会尝试做 ssh -Tvv ubuntu@X.X.X.X 并告诉它是怎么回事.

解决方案

首先帮自己一个忙,输入 git config --global push.default simple 以免看到第一部分错误.

其次,如果你能用ssh ubuntu@X.X.X.X登录成功,那么你的key就可以了,还有实例名.

如果你不能,你可以:

  • 尝试一个 ssh -Tvv ubuntu@X.X.X.X 看看发生了什么,然后
  • 通过转到服务器来验证这一点,停止 sshd 并在调试模式下重新启动它 (/usr/sbin/sshd -d):它将只接收一个 ssh 连接:尝试从您的客户端 ssh ubuntu@XXXX,您应该会看到 sshd 响应.
    然后正常重启sshd.
<小时>

在您的情况下,您必须使用在 ~/.ssh/config 中定义的别名,因为您的密钥不是标准密钥.

为了顺利推送,做一个git push -u deploy master.

由于 git remote -v 返回:

deploy ssh://ubuntu@X.X.X.X/home/ubuntu/repo (fetch)部署 ssh://ubuntu@X.X.X.X/home/ubuntu/repo(推送)

这意味着您没有使用 ssh 别名.

类型:

git remote set-url deploy myAlias:/home/ubuntu/repo

(语法很重要:myAlias: 后跟 repo 路径)

然后再试一次git push.

I know that a lot of similar questions exist here (and I read a lot of them before posting this one), but this one is different, so please stay with me for a while.

Few days ago I configured my remote git repository on amazon ec2. After hours of struggling I made it working and was able to push files there. I was working with it for a day or two pushing resources to it without any problems (I saw every update properly).

Today, for some reason I can not push anything to it from my local machine.

git push deploy ends up with the following error message (the same one I see when I try to get info about deploy: git remote show deploy):

warning: push.default is unset; its implicit value is changing in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the current behavior after the default changes, use:

  git config --global push.default matching

To squelch this message and adopt the new behavior now, use:

  git config --global push.default simple

See 'git help config' and search for 'push.default' for further information.
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
'current' instead of 'simple' if you sometimes use older versions of Git)

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

The first part of it (before permission denied) I was able to see previously, but it was still pushing everything correctly back then.

Deploy exist because I can clearly see it with git remote -v:

deploy  ssh://ubuntu@X.X.X.X/home/ubuntu/repo (fetch)
deploy  ssh://ubuntu@X.X.X.X/home/ubuntu/repo (push)

I can correctly ssh to my server, also my private key has 0400 permissions. On both machines I have ubuntu 12.04 LTS.

I thought that may be there is some problem with my public key, so I went ahead and recreate it from private key: ssh-keygen -y -f key.pem > key.pub. Based on its sha it is identical to my previous public key: sha1sum key_prev.pub = sha1sum key.pub

I still went to the server and added a new key to authorized keys as well.

Still no changes. I can not push anything. Can anyone tell me what is the problem here and why it happened? Do I need to do anything with my local .ssh/known_hosts?

Also in one of the answers I found the following:

Please note that after restarting the instance, the dns name changed. I fell for this several times. The keyfile was still valid, but the "servername" changed.

I actually restarted my machine, so I think this is highly relevant. The problem is that I can not understand what should I change now.

After reading the answer of VonC.

I can not ssh to the server by doing ssh ubuntu@X.X.X.X (I got Permission denied (publickey).), but I can do this with ssh myAlias, where myAlias is defined in ~/.ssh/config

Host            myAlias
Hostname        X.X.X.X
User            ubuntu
IdentityFile    path/to/mypem/file.pem

When I have done git config --global push.default simple I have another problem when doing git push deploy:

fatal: The current branch master has no upstream branch. To push the current branch and set the remote as upstream, use

git push --set-upstream deploy master

I will try to do ssh -Tvv ubuntu@X.X.X.X and will tell how it goes.

解决方案

First, do yourself a favor, and type git config --global push.default simple in order to not see the first part of the error.

Second, if you can login successfully with ssh ubuntu@X.X.X.X, then your keys are fine, as well as the instance name.

If you can not, you can:

  • try a ssh -Tvv ubuntu@X.X.X.X to see what is going one, and
  • verify that by going to the server, stopping sshd and restarting it in debug mode (/usr/sbin/sshd -d): it will receive only one ssh connection: try a ssh ubuntu@X.X.X.X from your client, and you should see the sshd response.
    Then restart sshd normally.

In your case, you have to use your alias, defined in ~/.ssh/config, since your key isn't a standard one.

For the push to go smoothly, do a git push -u deploy master.

Since git remote -v returns:

deploy  ssh://ubuntu@X.X.X.X/home/ubuntu/repo (fetch)
deploy  ssh://ubuntu@X.X.X.X/home/ubuntu/repo (push)

That means you are not using the ssh alias.

Type:

git remote set-url deploy myAlias:/home/ubuntu/repo

(The syntax is important: myAlias: followed by the repo path)

And then try again the git push.

这篇关于向亚马逊 ec2 推送提交时权限被拒绝(公钥)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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