0

I need to have two GitHub accounts on my computer, one personal, and one for work. I browsed the internet to find a solution to not be obligated to retype my credentials every time, and I stumbled upon this tutorial explaining the SSH system. That entirely correspond to my need.

Situation: I can push/pull from existing projects. That would suggest that the SSH keys/config are working well.

Problem: I can't push when it comes to a new project. If it is a new project (also created as described in the tutorial), the push returns the following error:

xxx@xxx:~path/to/repo$ git push -u origin master
ERROR: Repository not found.
fatal: Could not read from remote repository.

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

This is the git config -l on the repo:

xxx@xxx:~path/to/repo$ git config -l
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
user.email=<email>
user.name=<username>
remote.origin.url=git@github.com-<username>:<username>/test.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*

And to be exhaustive, here is the SSH config file:

# Work account
Host github.com-<username1>
    HostName github.com
    User git
    IdentityFile /path/to/ssh/key1
    IdentitiesOnly yes

# Personal account
Host github.com-<username2>
    HostName github.com
    User git
    IdentityFile /path/to/ssh/key2
    IdentitiesOnly yes

Obviously, and in the repo are the same as the ones in the SSH config file, I checked that a couple of times.

Configuration:

  • Ubuntu 20.04.3 LTS
  • git version 2.25.1
  • (let me know if there are additional information needed)

I found some other persons having a similar problem online, but the solution was never satisfactory in my case... (Either the SSH key was not added, which is not my case, or change from SSH to HTML, which is not possible if I want to use the SSH keys, as far as I have understood)

Thanks for any of your ideas!

  • Your setup *looks* correct. In general the next debug steps to use, if `git push -u origin master` isn't working, are: `git config --get remote.origin.pushurl` (get the "push URL"), `git config --get remote.origin.url` (get the "general URL"); use whichever one is not empty. Run `ssh -Tvvv user@host` with the user@host part from the URL you got; observe the output. Note that since you have `User git` in the config, you can just set the URL to `github.com-username1` or whatever and `ssh -Tv github.com-username1` to test. – torek Oct 07 '21 at 02:17
  • `git config --get remote.origin.pushurl` is empty `git config --get remote.origin.url` isn't `ssh -Tvvv user@host` displays a massive message, which I don't really know how to interpret, but I get this in the final lines: `Transferred: sent 3680, received 3232 bytes, in 0.2 seconds` `Bytes per second: sent 19373.5, received 17015.0` `debug1: Exit status 1`. If you need additional information in the result of this command, please tell me –  Oct 08 '21 at 10:50
  • The last few messages from ssh are uninteresting here. The *interesting* ones are where it negotiates with GitHub, sends various public keys, and gets responses from GitHub as to whether those keys are accepted. With no `-v` options you get a minimal amount of output, but if things aren't working, you don't get the intermediate diagnostics that might help tell *why* things are not working... – torek Oct 08 '21 at 19:11
  • `debug1: Authentication succeeded (publickey).` `Authenticated to github.com ([140.82.121.3]:22).` After searching through the whole response, I found these which I think should be relevant. If I understand it well, I should then be able to do everrything an authenticated user can, isn't it? –  Oct 09 '21 at 17:00
  • The "authentication succeeded" part means that they recognized that key, yes. There should be, from GitHub, a line of the form "Hi ! You've successfully authenticated, but GitHub does not provide shell access." The part is who GitHub think you are, so from here on, you should be able to get at any repositories that they have listed as accessible by . – torek Oct 09 '21 at 18:48
  • Note that they—GitHub—deduce *who you are* by *which of the keys you send them fit the lock **first***. So any keys you sent earlier that didn't work are irrelevant, and any keys you might try later are irrelevant. The one that did work is what makes you "you", to them. – torek Oct 09 '21 at 18:49
  • I have this message ("Hi ...") for both my accounts, no problem. But it seems like the push to a new repo is not possible and I don't know why! And, as the SSH "address" to my repo follows a certain format, the conf file should be used to identify the operation as authentic automatically! The other key shouldn't be used at any point if I understood correctly (in this particular repo, with this setup, obviously it should be used in other cases if needed, that is the goal) –  Oct 10 '21 at 21:12
  • OK - looks like you're getting authenticated properly. And yes, the `IdentitiesOnly` line is supposed to make sure you send only the keys listed in the `IdentityFile` lines (you can list more than one, though here, that doesn't make any sense to do). As for the "new repo": you've used the GitHub web interface to create a new empty repository? And you've given access *to* that repository, to this user? As far as I know GitHub will only create a new repository via their web interface. – torek Oct 10 '21 at 23:20
  • I created the repo via the Python API, and I try to push with the exact same credentials as the ones used by the API to create the repo. (The SSH credentials are the same as the ones used by the Python script) –  Oct 15 '21 at 19:56
  • I know nothing about this Python API, but it seems like it would be a good idea to use the web interface (through a browser) to verify that everything else looks right. If so, that points to the Python API as the problem. – torek Oct 15 '21 at 21:39
  • In fact, the repo on GitHub is created, I verified this. I will try to push via http and see if this works. If it doesn't, then the repo doesn't have the correct rights attributed, if it does though, I will have no idea what the problem is –  Oct 16 '21 at 10:10

0 Answers0