简体   繁体   English

无法推送到我服务器上的git存储库

[英]Unable to push to git repository on my server

I want to have two git repositories on my server. 我想在服务器上有两个git存储库。 One of them belongs to someone else. 其中之一属于其他人。 I copy their ssh keys onto my account: 我将其ssh密钥复制到我的帐户中:

sudo cp /home/otheruser/.ssh/id_rsa id_rsa
sudo cp /home/otheruser/.ssh/id_rsa.pub id_rsa.pub
git clone git@github.com:otheruser/Gateway.git
git remote show origin
* remote origin
Fetch URL: git@github.com:otheruser/Gateway.git
Push  URL: git@github.com:otheruser/Gateway.git
HEAD branch: master
Remote branches:
...

Now I want to copy some of these branches into my own git account: 现在,我要将其中一些分支复制到我自己的git帐户中:

git remote add tempgateway git@github.com:myuser/TemporaryGateway.git
git remote -v
origin  git@github.com:otheruser/Gateway.git (fetch)
origin  git@github.com:otheruser/Gateway.git (push)
tempgateway git@github.com:myuser/TemporaryGateway.git (fetch)
tempgateway git@github.com:myuser/TemporaryGateway.git (push)

But it appears at the moment that ssh authentication fails when I try to reach my git repository: 但是,当我尝试访问git存储库时,似乎ssh身份验证失败:

git remote show tempgateway
ERROR: Repository not found.
fatal: The remote end hung up unexpectedly

So I generate ssh keys: 所以我生成ssh密钥:

ssh-keygen -t rsa -f ~/.ssh/tempgateway.id_rsa
ls -l
-rw------- 1 myuser myuser 1675 2014-01-02 15:39 id_rsa
-rw-r--r-- 1 myuser myuser  399 2014-01-02 15:41 id_rsa.pub
-rw-r--r-- 1 myuser myuser 1768 2014-01-02 16:22 known_hosts
-rw------- 1 myuser myuser 1679 2014-01-02 16:55 tempgateway.id_rsa
-rw-r--r-- 1 myuser myuser  401 2014-01-02 16:55 tempgateway.id_rsa.pub

Then I add the config file and enter the following: 然后添加配置文件并输入以下内容:

Host github.com
    HostName github.com
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/id_rsa

Host tempgateway.github.com
    HostName github.com
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/tempgateway.id_rsa

I add to ssh: 我添加到ssh:

ssh-add ~/.ssh/id_rsa
ssh-add ~/.ssh/tempgateway.id_rsa

ssh-add -l ssh-add -l

2048 cb:cf:15:9d:6d:73:ac:d0:b2:8e:df:xx:xx:xx:xx:xx ~/.ssh/id_rsa (RSA)
2048 cd:f3:f8:2e:8d:53:3e:59:1b:38:68:xx:xx:xx:xx:xx ~/.ssh/tempgateway.id_rsa (RSA)

Then add the public key for tempgateway to my github account. 然后将tempgateway的公钥添加到我的github帐户。

To test I've done this all correctly, I did the following check: 为了测试我是否正确完成了所有操作,我进行了以下检查:

ssh -T git@tempgateway.github.com
Hi MyUser! You've successfully authenticated, but GitHub does not provide shell access.
ssh -T git@github.com
Hi OtherUser! You've successfully authenticated, but GitHub does not provide shell access.

Now while I am able to show remotes still for origin, when I try to show remotes for tempgateway I get the following still: 现在,虽然我仍然可以显示遥控器的原点,但是当我尝试显示tempgateway的遥控器时,我仍然得到以下信息:

git remote show tempgateway
ERROR: Repository not found.
fatal: The remote end hung up unexpectedly

git push tempgateway origin/master
ERROR: Repository not found.
fatal: The remote end hung up unexpectedly

Why am I able to ssh into that git repository, but I cannot show the origin or push to it? 为什么我可以ssh进入该git存储库,但无法显示源或将其推入?

If the SSH access is working, as you have shown it to be, then I would ensure the new remote repo is initialized (or copied) properly. 如果SSH访问正常(如您所显示的那样),那么我将确保正确初始化(或复制)新的远程存储库。 If not, then git will not recognise it as a repo. 如果不是,则git不会将其识别为存储库。

Edit: 编辑:

Sorry, I didn't notice you are using github. 抱歉,我没有注意到您正在使用github。 You won't need to bother with the above then. 然后,您将无需再理会以上内容。

But I did notice that in using different SSH key pairs for the two accounts, you haven't made use of tempgateway.github.com when you ran the config commands in setting up the new remote repository. 但是我确实注意到,在为两个帐户使用不同的SSH密钥对时,当您在设置新的远程存储库中运行config命令时并未使用tempgateway.github.com Try editing .git/config and using the new SSH identity name you created in the remote URL. 尝试编辑.git / config并使用您在远程URL中创建的新SSH身份名称。

The output of the git remote -v command should probably be more like git remote -v命令的输出应该更像

tempgateway git@tempgateway.github.com:myuser/TemporaryGateway.git (fetch)
tempgateway git@tempgateway.github.com:myuser/TemporaryGateway.git (push)

than

tempgateway git@github.com:myuser/TemporaryGateway.git (fetch)
tempgateway git@github.com:myuser/TemporaryGateway.git (push)

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

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