0

I have generated an SSH key on my work laptop (ssh-keygen -t ed25519 -C "me@my-personal-email.org") and added it to the list of SSH keys of my personal repository. Yet when I try to git push to this personal repo (from my work laptop) I get the message:

ERROR: Repository not found.
fatal: Could not read from remote repository.

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

I also added these lines to the repo .git/config:

[user]
    name = MY NAME
    email = me@my-personal-email.org

... and I get the same error.

The repo definitely exists and I thought I had set up access... what could I be missing?

Peter B
  • 453
  • 4
  • 15
  • 1
    The `user.name` and `user.email` settings are arbitrary strings that you can change at any time and are *not used for authentication*. To see how authentication works with ssh, see, e.g., [this answer](https://stackoverflow.com/a/69920641/1256452). To *debug* ssh authentication, consider using `ssh -Tv`; see [here](https://stackoverflow.com/a/38706495/1256452) for example. – torek Feb 06 '22 at 08:08

1 Answers1

1

Check if you have done the step to add the SSH key to the SSH agent:

# start the ssh-agent in the background
$ eval "$(ssh-agent -s)"
> Agent pid 59566

and, then

$ ssh-add ~/.ssh/id_ed25519

Essentially, you need to inform git which private key you will be using for the git connection.

Host One
    HostName ssh.github.com
    IdentityFile ~/.ssh/id_rsa
    User git

Host Two
    HostName ssh.<enterprise>.github.com
    IdentityFile ~/.ssh/id_rsa
    User git

References

Abdullah Khilji
  • 370
  • 2
  • 8
  • These pages seem to be telling me how to set up ssh in *all* situations. But I only want to use this new ssh key when I am connecting to my personal github account, which I will only be doing when running git in that particular directory. Can you confirm that these solutions will not affect git when I am using my work github account? – Peter B Feb 06 '22 at 10:47
  • Check your git remote by `git remote -v`, the SSH key will then be picked up corresponding to the host set in `~/.ssh/config` – Abdullah Khilji Feb 06 '22 at 11:13
  • git remote -v looks correct: it gives the address of the repo on githib. There is no ~/.ssh/config file. p.s. It is late in my time zone so I may not reply to you again for a while. – Peter B Feb 06 '22 at 11:23
  • Sure Peter, the config file tells the git which key and host to match. You may try updating them with the required values, so that only the private key matching with the respective host is used to interact with the git ssh server. – Abdullah Khilji Feb 06 '22 at 13:44