0

I have two github accounts and their user names are as so :

subhayan-bhattacharya
subhayan-test

Now i want to do work(push/pull) in both the repositories using the same machine. Hence i have set up two ssh keys for this . The default one points to subhayan-bhattacharya account.

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

I have added the relevant ssh keys to the ssh and gpg keys section of the respective git hub accounts.

My .ssh/config file looks like this:

7tvmb228:.ssh subhayan.bhattachary$ vi config

Host *
   AddKeysToAgent yes
   UseKeychain yes

The problem is i am not being able to push to the subhayan-test account . I tried like so :

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.

~

I dont know why it says that permission denied to subhayan-bhattacharya since this is the other git hub account name.

However the push and pull to the other account works normally.

What should i check and why this does not seem to work.

Subhayan Bhattacharya
  • 5,407
  • 7
  • 42
  • 60
  • 1
    Possible duplicate of [Multiple GitHub Accounts & SSH Config](https://stackoverflow.com/questions/3225862/multiple-github-accounts-ssh-config) – phd Jul 20 '19 at 23:08
  • https://stackoverflow.com/search?q=%5Bgithub%5D+multiple+accounts – phd Jul 20 '19 at 23:08

1 Answers1

0

Your config should include, for the second account:

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

Then in your repository:

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

If you need to push to subhayan-test/starter-web.git instead, make sure (independently of any SSH key) to add subhayan.bhattachary as a collaborator

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250