无法将文件从同一台机器推送到第二个github存储库

时间:2019-07-20 22:17:47

标签: git ssh ssh-keys

我有两个github帐户,它们的用户名是这样的:

subhayan-bhattacharya
subhayan-test

现在,我想使用同一台机器在两个存储库中进行工作(推/拉)。因此,我为此设置了两个ssh密钥。默认帐户指向subhayan-bhattacharya帐户。

total 48
drwx------   8 subhayan.bhattachary  1796758494   256 Jul 20 23:46 .
drwxr-xr-x+ 38 subhayan.bhattachary  1796758494  1216 Jul 20 23:46 ..
-rw-r--r--   1 subhayan.bhattachary  1796758494    50 Jul 20 23:31 config
-rw-------   1 subhayan.bhattachary  1796758494  3401 Jun 14 15:28 id_rsa
-rw-r--r--   1 subhayan.bhattachary  1796758494   755 Jun 14 15:28 id_rsa.pub
-rw-r--r--   1 subhayan.bhattachary  1796758494   990 Jul  5 13:36 known_hosts
-rw-------   1 subhayan.bhattachary  1796758494  1856 Jul 20 23:41 newkeys
-rw-r--r--   1 subhayan.bhattachary  1796758494   421 Jul 20 23:41 newkeys.pub

我已将相关的ssh密钥添加到相应的git hub帐户的ssh和gpg密钥部分。

我的.ssh / config文件如下所示:

7tvmb228:.ssh subhayan.bhattachary$ vi config

Host *
   AddKeysToAgent yes
   UseKeychain yes

问题是我无法推送到subhayan-test帐户。我这样尝试过:

7tvmb228:starter-web subhayan.bhattachary$ ssh-add ~/.ssh/newkeys
Identity added: /Users/subhayan.bhattachary/.ssh/newkeys (subhayan.bhattachary@7tvmb228.fritz.box)
7tvmb228:starter-web subhayan.bhattachary$ git push
ERROR: Permission to subhayan-test/starter-web.git denied to subhayan-bhattacharya.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

我不知道为什么它说对subhayan-bhattacharya的权限被拒绝,因为这是另一个git hub帐户名。

但是,推到另一个帐户的功能正常。

我应该检查什么以及为什么它似乎不起作用。

1 个答案:

答案 0 :(得分:0)

您的配置应包含第二个帐户:

Host bhat
  Hostname github.com
  User git
  IdentityFile /.ssh/newkeys

然后在您的存储库中:

cd /path/to/repo
git remote add bhat bhat:subhayan.bhattachary/starterweb.git
git push bhat master

如果您需要推送到subhayan-test/starter-web.git,请确保(独立于任何SSH密钥)推送到add subhayan.bhattachary as a collaborator

相关问题