• Skip to main content
  • Skip to primary sidebar
  • Skip to footer

Notes to Self

  • Aviation Weather from NOAA Plugin
    • KZZV
    • Bad Shortcode
    • Simple Metar
  • Meetings

Mark Chouinard / December 23, 2014

2 GitHub Accounts, 1 Mac

I wanted to test out pull requests triggering Travis-ci.  I figured I’d use an old account to fork, edit and create a pull request for one of my repos.  I had set the local config before adding the remote and pulling, but when I tried to push, I got denied based on my global GitHub username.  Turns out I just needed to add the second key to ssh-agent, edit my ssh config file and make a small adjustment to the local git config  file.

Adding your key to ssh-agent prompts for any private key password and ssh-agent should use that and not prompt you for it when connecting elsewhere with SSH or SCP.

You can list all keys loaded in ssh-agent

ssh-add -l

Add the second key if needed

ssh-add ~/.ssh/second_key

Edit your SSH config file

vi ~/.ssh/config

Create an alias for github.com that will use the second ssh key

#Second Github Account
Host github.com-alt
HostName github.com
User SecondUserName
IdentityFile ~/.ssh/second_key

Setup local git config as usual, just don’t use –global

git config user.name 'Second Name'
git config user.email [email protected]
git config github.user SecondUsername

and in .git/config, change github.com to the alias set previously

[remote "origin"]
url = [email protected]:secondUserName/project.git

Now running git push origin master  works as expected.

Filed Under: Command Line Tagged With: github, ssh

Primary Sidebar

Post Archives

  • June 2024
  • December 2022
  • July 2022
  • December 2021
  • October 2021
  • June 2021
  • February 2021
  • October 2020
  • September 2020
  • August 2020
  • March 2020
  • February 2020
  • December 2019
  • September 2019
  • June 2017
  • May 2016
  • April 2016
  • March 2016
  • September 2015
  • August 2015
  • February 2015
  • January 2015
  • December 2014
  • November 2014
  • October 2014
  • September 2014
  • August 2014
  • July 2014
  • May 2014
  • April 2014
  • March 2014
  • February 2014
  • January 2014
  • June 2013
  • May 2013
  • April 2013
  • February 2013
  • January 2013
  • December 2012
  • January 2011

Footer

Copyright © 2025 · machouinard · Log in