Use secondary key to push to invited repo

I have two github accounts on my computer: one for work and one for my personal account.
(I’m on a mac)
My .ssh config file:

Host *
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/id_rsa

Host github.com-personalAccount
  HostName github.com
  User git
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/id_personal

This works fine. I added the ssh key to my github account. I can push to my personal repos just fine, and push to work repos as well.

Now, I’ve been invited as a collaborator to a third repo, and I’ve accepted the invitation. I figured I could use my personal ssh key:

Host *
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/id_rsa

Host github.com-personalAccount
  HostName github.com
  User git
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/id_personal

Host github.com-otherUserAccount
  HostName github.com
  User git
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/id_personal

Then, in the repo:

git remote add origin git@github.com:otherUserAccount/redacted.git
git add .
git commit -m "Initial commit"
git push -u origin master

But it doesn’t work. I get this error:

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’ve double and triple checked. The repo address is correct.

Please help!

Thanks in advance!

On which account did you accept the invitation? That almost looks like it’s a supposed to be a third one, and you can’t use the same SSH key for more than one account.

Also, ssh -vT github.com-otherUserAccount should tell you which user (if any) you get recognized as.

1 Like

I accepted it on my personal account.

I’ve verified that: I can see the other user’s repo from my personal account, but not from my work account.

ssh -vT github.com-otherUserAccount

debug1: Reading configuration data /Users/localUser/.ssh/config
debug1: /Users/localUser/.ssh/config line 1: Applying options for *
debug1: /Users/localUser/.ssh/config line 13: Applying options for github.com-otherUserAccount
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 47: Applying options for *
debug1: Connecting to github.com port 22.
debug1: Connection established.
debug1: identity file /Users/localUser/.ssh/id_rsa type 0
debug1: identity file /Users/localUser/.ssh/id_rsa-cert type -1
debug1: identity file /Users/localUser/.ssh/id_personalAccount type 3
debug1: identity file /Users/localUser/.ssh/id_personalAccount-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.1
debug1: Remote protocol version 2.0, remote software version babeld-2aa5ef1f
debug1: no match: babeld-2aa5ef1f
debug1: Authenticating to github.com:22 as 'git'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: rsa-sha2-512
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ssh-rsa SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8
debug1: Host 'github.com' is known and matches the RSA host key.
debug1: Found key in /Users/localUser/.ssh/known_hosts:1
debug1: rekey out after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey in after 134217728 blocks
debug1: Will attempt key: /Users/localUser/.ssh/id_rsa RSA SHA256:TiWXiaODf8yydxTOB4/TrpqQR+xpr9m2rZEBNUL6O7g explicit agent
debug1: Will attempt key: /Users/localUser/.ssh/id_personalAccount ED25519 SHA256:tprsGii9zl+digy4IcEXOzdp2YbB0sShlg6VPC5Nd0w explicit
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519-cert-v01@openssh.com,ecdsa-sha2-nistp521-cert-v01@openssh.com,ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp256-cert-v01@openssh.com,sk-ssh-ed25519-cert-v01@openssh.com,sk-ecdsa-sha2-nistp256-cert-v01@openssh.com,rsa-sha2-512-cert-v01@openssh.com,rsa-sha2-256-cert-v01@openssh.com,ssh-rsa-cert-v01@openssh.com,ssh-dss-cert-v01@openssh.com,sk-ssh-ed25519@openssh.com,sk-ecdsa-sha2-nistp256@openssh.com,ssh-ed25519,ecdsa-sha2-nistp521,ecdsa-sha2-nistp384,ecdsa-sha2-nistp256,rsa-sha2-512,rsa-sha2-256,ssh-rsa,ssh-dss>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering public key: /Users/localUser/.ssh/id_rsa RSA SHA256:TiWXiaODf8yydxTOB4/TrpqQR+xpr9m2rZEBNUL6O7g explicit agent
debug1: Server accepts key: /Users/localUser/.ssh/id_rsa RSA SHA256:TiWXiaODf8yydxTOB4/TrpqQR+xpr9m2rZEBNUL6O7g explicit agent
debug1: Authentication succeeded (publickey).
Authenticated to github.com ([140.82.114.3]:22).
debug1: channel 0: new [client-session]
debug1: Entering interactive session.
debug1: pledge: network
debug1: client_input_global_request: rtype hostkeys-00@openssh.com want_reply 0
debug1: Sending environment.
debug1: Sending env LANG = en_US.UTF-8
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
Hi workUserName! You've successfully authenticated, but GitHub does not provide shell access.
debug1: channel 0: free: client-session, nchannels 1
Transferred: sent 3452, received 3360 bytes, in 0.2 seconds
Bytes per second: sent 20177.1, received 19639.4
debug1: Exit status 1

So, it looks as though it’s accepting the public key associated with my work account? Amy I reading that correctly?

That doesn’t make sense to me.

Looks like it, and the log also says which key was used:

Must be the order of configuration statements, try moving the Host * section to the end of the file. The ssh_config manual page states:

For each parameter, the first obtained value will be used.