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

时间:2014-01-02 23:28:23

标签: git github ssh

我想在我的服务器上安装两个git存储库。其中一个属于其他人。我将他们的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:
...

现在我想将其中一些分支复制到我自己的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)

但是当我尝试访问我的git存储库时,ssh身份验证失败了:

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

所以我生成了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

然后我添加配置文件并输入以下内容:

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

我添加到ssh:

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

ssh-add -l <​​/ p>

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)

然后将tempgateway的公钥添加到我的github帐户。

为了测试我已经完成了所有这些,我做了以下检查:

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.

现在虽然我能够显示遥控器仍然是原点,当我尝试显示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

为什么我能够进入那个git存储库,但我无法显示原点或推送它?

1 个答案:

答案 0 :(得分:0)

如果SSH访问正常,正如您所示,那么我将确保正确初始化(或复制)新的远程仓库。如果没有,那么git将不会将其识别为回购。

编辑:

抱歉,我没注意到你在使用github。你不需要为此而烦恼。

但我确实注意到在为这两个帐户使用不同的SSH密钥对时,在设置新的远程存储库时运行config命令时没有使用tempgateway.github.com。尝试编辑.git / config并使用您在远程URL中创建的新SSH身份名称。

git remote -v命令的输出应该更像

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

大于

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