5

So I'm now "jononomo" on github. A year ago, however, I was "zononomo". I quit software for a while and bought a new laptop in the interim. Then I came back and created a new account on Github under the handle "jononomo" and now I'm trying to sync my dotfiles between my two laptops. From my new laptop I created a git repository and pushed it up to github where it can be viewed under the "jononomo" account. Then I went to my old laptop and cloned this repository. Everything worked as expected.

Then I made some changes to my dotfiles on my old laptop and now I'd like to push these changes to github so that I can then pull them down to my new laptop. The problem is that when I run the command:

git push origin master

I get the error message:

ERROR: Permission to jononomo/.dotfiles.git denied to zononomo.

The first thing I did was blow away my old SSH keys in ~/.ssh/id_rsa and ~/.ssh/id_rsa.pub. Then I generated new SSH keys and added my new public key to my jononomo github account. But that didn't fix the problem. If I run the command:

ssh -T git@github.com

I get the response:

Hi zononomo! You've successfully authenticated, but GitHub does not provide shell access.

Next, I followed the solution given here: https://stackoverflow.com/a/8152291/1701170 This person suggested that I create a ~/.ssh/config file with the following contents:

Host github-jononomo
    User git
    Hostname github.com
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/id_dsa.pub

and then he suggested I run the command:

git remote set-url origin git@github-jononomo:jononomo/.dotfiles.git

I tried that, but it didn't fix my issue. I'm still getting the message:

ERROR: Permission to jononomo/.dotfiles.git denied to zononomo.

Incidentally, my .gitconfig has the following contents:

[user]
    name = Jon Crowell
    email = me@myemail.com
[github]
    user = jononomo
    token = 2a18a7235746324aefec34b234aa343a
    email = me@myemail.com
[credential]
    helper = osxkeychain
Community
  • 1
  • 1
tadasajon
  • 14,276
  • 29
  • 92
  • 144
  • 1
    Please don't edit your answers into the question. You need to post them *as answers*, so they can be accepted. It is completely acceptable to post and accept an answer to your own question. – user229044 Oct 26 '12 at 19:17
  • Ack, you deleted my answer but didn't re-post it anywhere! Maybe I can find a cached version of the page... – tadasajon Oct 26 '12 at 19:23
  • okay, I've re-posted the answer below after retrieving it from the old revision. I guess now someone can vote and give me reputation, so thanks for the tip, meagar. – tadasajon Oct 26 '12 at 19:27
  • Click the "X minutes ago" above my name to review the entire edit history of your question. You can do this for any post on the site... – user229044 Oct 26 '12 at 19:27

2 Answers2

4

I got it to work by taking the following steps:

First my ~/.ssh/config file is as follows:

Host github-jononomo
    HostName github.com
    User git
    IdentityFile  ~/.ssh/id_rsa
    IdentitiesOnly yes

Second, I ran the command git remote set-url origin git@github-jononomo:jononomo/.dotfiles.git

Third, I ran the command ssh -T git@github.com and got the result Hi jononomo! You've successfully authenticated, but GitHub does not provide shell access.

Fourth, I logged in to my old github account, removed the SSH key and completely deleted the account.

Many thanks to VonC.

tadasajon
  • 14,276
  • 29
  • 92
  • 144
3

zononomo? GitHub shouldn't recognize you as zononomo anymore.
Maybe you have an ssh agent delivering your old key?

As suggested in "Having Trouble Switching Github accounts on terminal", add the line:

 IdentitiesOnly yes

to your config file and see if GitHub is still using that old id.

however I'm still getting the

 ssh: Could not resolve hostname github: nodename nor servname provided, or not known error

The "hostname" to resolve must match the Host entry of the config file.

If that Host entry is github-jononomo, you must use it in your ssh address as well:

git remote set-url origin github-jononomo:jononomo/.dotfiles.git
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I logged into my old github account, removed the SSH stuff, then completely deleted the account. Now I'm getting a different error: "ssh: Could not resolve hostname github: nodename nor servname provided, or not known" I'll try your suggestion right now... – tadasajon Oct 26 '12 at 18:34
  • Okay, I added a config file to my `~/.ssh/` directory. It contains the following text: `Host github.com User git IdentityFile ~/.ssh/id_rsa IdentitiesOnly yes` -- however I'm still getting the `"ssh: Could not resolve hostname github: nodename nor servname provided, or not known` error. I guess I'll start googling that error now. – tadasajon Oct 26 '12 at 18:40
  • 1
    @JonCrowell you need to use the entry you put on Host: github-jononomo. So use `git remote set-url origin github-jononomo:jononomo/.dotfiles.git`, and make sure to use `github-jononomo` as `Host`, while keeping hostname to `github.com` – VonC Oct 26 '12 at 18:49
  • @JonCrowell you probably did it, but check your email also: http://stackoverflow.com/questions/12597096/git-github-remembers-wrong-account/12597211#12597211 – VonC Oct 26 '12 at 18:52
  • @JonCrowell see as examples of config file: http://stackoverflow.com/questions/9551448/change-github-account-mac-command-line/9551540#9551540, or http://stackoverflow.com/questions/12066895/how-to-work-on-personal-github-repo-from-office-computer-whose-ssh-key-is-alread/12066973#12066973 or http://stackoverflow.com/questions/10041082/how-to-add-deploy-key-for-2-repo-with-1-user-on-github/10042145#10042145 – VonC Oct 26 '12 at 18:54
  • @JonCrowell or use an https address ;) http://stackoverflow.com/questions/5377703/syncing-with-github/5378094#5378094 – VonC Oct 26 '12 at 18:56
  • Okay, I got it to work. I will post a note to the bottom of my question that will give the steps I took. I had to get the `~/.ssh/config` file correct, I guess. – tadasajon Oct 26 '12 at 19:04
  • The `git remote set-url origin` is a must-do after setting hostname in `~/.ssh/config` – Sophia Feng Oct 17 '14 at 05:49