简体   繁体   English

从 EC2 ubuntu 推送到 github

[英]Push to github from EC2 ubuntu

when I run the following it seems successful:当我运行以下命令时,它似乎成功了:

$ sudo ssh -T git@github.com
Hi x! You've successfully authenticated, but GitHub does not provide shell access.

However, when I do a sudo git push from my repo, it doesn't work I get但是,当我从我的回购中执行sudo git push时,它不起作用我得到

Permission denied (publickey).
fatal: The remote end hung up unexpectedly

Can anyone help here?有人可以帮忙吗?

The facts that you are running that on EC2 shouldn't matter at all.您在 EC2 上运行的事实根本不重要。 You are facing here an issue of an incorrect setup of ssh key and/or initially cloning the repo with the wrong user.您在这里面临 ssh 密钥设置不正确和/或最初使用错误用户克隆回购的问题。

Whatever you do, there should be absolutely no need to use sudo.无论您做什么,绝对不需要使用 sudo。 You should be able to clone the repo using an ordinary user.您应该能够使用普通用户克隆回购协议。 If that doesn't work, make sure to generate a new ssh key for this user and add it to the repo.如果这不起作用,请确保为此用户生成一个新的 ssh 密钥并将其添加到存储库中。 If如果

ssh -T git@github.com

is working again for this user, try to clone the repo again.再次为这个用户工作,尝试再次克隆回购协议。 If that works, check if you can push to it.如果可行,请检查您是否可以推动它。

If you are still running into problems, make sure you followed the install guide for Linux provided by GitHub .如果您仍然遇到问题,请确保您遵循了GitHub 提供的 Linux 的安装指南 Everything written there works also on an Ubuntu version without graphical frontend.那里写的所有内容也适用于没有图形前端的 Ubuntu 版本。

I was having this same issue on my AWS EC2 Ubuntu instance and I just ended up solving it with a push in the right direction from this blog post .我在我的 AWS EC2 Ubuntu 实例上遇到了同样的问题,我只是通过从这篇文向正确的方向推动来解决它。

What was happening for me was that root had access to the folder I was trying to clone into.对我来说发生的事情是root可以访问我试图克隆到的文件夹。

drwxr-xr-x 2 root root 4096 Apr 25 00:51 sites

Because of that, I had to do a sudo git clone... command because I didn't have write permissions to that folder as my default user.因此,我不得不执行sudo git clone...命令,因为我作为默认用户没有对该文件夹的写权限。

All I needed to do was give myself write access to the /sites folder我需要做的就是给自己写访问 /sites 文件夹

sudo chown -R ubuntu /sites

Which allowed me to omit the sudo in the git clone... command, which ran the git command as the user ubuntu .这让我可以省略git clone...命令中的 sudo,该命令以用户ubuntu的身份运行 git 命令。

This fixed it for me, and I think it's cause the files in my ~/.ssh folder were owned by ubuntu , and it had to be that user running the command.这为我修复了它,我认为这是因为我的~/.ssh文件夹中的文件归ubuntu所有,并且必须是运行该命令的用户。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM