Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I don't have ~/.ssh/config file but multiple GitHub accounts works, how?

I'm trying to configure another GitHub account to be able work from my machine. I started to looking around and I found:

Set up multiple ssh profiles by creating/modifying ~/.ssh/config. Note the slightly differing 'Host' values:

So as I (already) have multiple accounts working (I don't remember how and when I did that) I wanted to just add another entry in ~/.ssh/config. But it appears that I don't have such file. Maybe it is located somewhere else? Or maybe my machine is configured in some other way? Where to start searching?

like image 275
Marian Paździoch Avatar asked Mar 31 '18 12:03

Marian Paździoch


1 Answers

I wanted to just add another entry in ~/.ssh/config

You can create it, but:

  • you need to have generate public/private keys with a different name

    ssh-keygen -q -P "" -t rsa -f ~/.ssh/key2
    
  • you need to have registered ~/.ssh/key2.pub on your remote server second account

  • you need to have a config file with:

    Host github2
    HostName github.com
    User git
    IdentityFile /home/me/.ssh/key2
    

Note the User here: 'git', not 'another GitHub account'

  • you need to change the origin remote URL to use that entry:

    git remote set-url origin github2:MySecondAccount/MyRepo.git
    
like image 129
VonC Avatar answered Sep 20 '22 13:09

VonC