Why can I push to a private git repository even it's private

Viewed 51

I create a private repository on Github, when I try to clone it I can't (and that's what I was waiting for), but if I init a new git project on my local machine and set a remote origin url I can push my commits on this repo without any problem...

Is that normal ?

I was waiting that I have a forbidden error because I didn't give any access to the user I have on my local machine.

1 Answers

Indeed, I have two github accounts (let say A and B) and I my problem is why can I push commits with user A on my repository B which is private and the settings do not contain any ssh key of user A.

Then it is best to differentiate those two accounts, using two different SSH keys, registered each to their respective accounts.

Do that with a ~/.ssh/config file with:

Host githubA
  Hostname github.com
  User git
  IdentityFile ~/.ssh/keyA

Host githubB
  Hostname github.com
  User git
  IdentityFile ~/.ssh/keyB

Check that are working with:

ssh -Tv githubA
ssh -Tv githubB

And clone your repositorys with:

git clone githubA:A/repoFromA
git clone githubB:B/repoFromB

From there, a push from each local repository will use the right SSH key and will authenticate to GitHub with the right account.

Related