Mac OS (High Sierra) here. I have an SSH key, example-gh-user, and when I run pbcopy < ~/.ssh/example-gh-user.pub and paste it into an editor I see:
ssh-ed25519 <SOME_REALLY_LONG_ALPHANUM> [email protected]
Obviously for security reasons I am replacing the actual value of <SOME_REALLY_LONG_ALPHANUM> and [email protected] with the dummy values above. But everything looks ok.
On GitHub, I have a user, example-gh-user, that is using the [email protected] email, and I can log in with that user and see all my repos. Everything appears fine.
I have followed the GitHub guide on adding an SSH key to my example-gh-user GitHub account. Hence, this SSH key should be associated with the same email address that my GH account is associated with.
In my ~/.ssh/config file, I have the following entries:
Host example-dev
Hostname github2.com
AddKeysToAgent yes
IdentityFile ~/.ssh/example-gh-user
Host github.com
User git
Hostname github.com
AddKeysToAgent yes
PreferredAuthentications publickey
IdentityFile ~/.ssh/example-gh-user
So far, so good, I think.
However, when I run the following from the command line:
ssh -Tv [email protected]
I get a huge dump of output that ends, interestingly-enough, with this:
debug1: Sending environment.
debug1: Sending env LANG = en_US.UTF-8
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
Hi my-old-gh-user! You've successfully authenticated, but GitHub does not provide shell access.
debug1: channel 0: free: client-session, nchannels 1
Transferred: sent 3452, received 2724 bytes, in 0.1 seconds
Bytes per second: sent 28403.1, received 22413.1
debug1: Exit status 1
Look at that! my-old-gh-user! That's an old GH user that I haven't used in years!
Where is SSH and/or git/GitHub looking to grab that my-old-gh-user from?! Does SSH cache old data some how? If I understand how everything works correctly, ~/.ssh/config clearly directs SSH to use ~/.ssh/example-gh-user when connecting as git user to github.com, right? Where am I going awry?
Simply
go get github.com/SomeExampleOrg/some-service/client(assuming the original line is still ingo.mod)That will update
go.modto the latest for that repository, and the go.mod line about client will display the latest version available.If that repository is a public one, Go will use the normal HTTPS URL, and your SSH configuration won't be needed.
TheOP mentions in the discussion
By default, ssh will look for
~/.ssh/id_rsa(.pub). If that old public kay was registered to the old GitHub user account SSH profile setting (as documented by GitHub), that would explain why SSH identifies you by default with the old GitHub account.Register a new public key in your new account, and make sure to replace the default one by your new key (or use an
~/.ssh/configfile), and SSH will aithenticate you kwith the new account.Then you need to add to your
~/.ssh/configfile:Then